How to get the Datediff between two fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dougancil
    Contributor
    • Apr 2010
    • 347

    How to get the Datediff between two fields

    I'm trying to get the datediff (in minutes) between two fields in a database. These fields are going to be supplied by an end user so they can be any number or any day. The two fields are starttime and endtime and the table name is Exceptions. Can anyone offer a way to do this? I'm using SQL 2000.

    Thank you,

    Doug
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    Books online gives you the syntax
    its along the lines of
    Code:
    Select 
    DateDiff(mm, starttime, IsNull(endtime, starttime))
    From Exceptions

    Comment

    • dougancil
      Contributor
      • Apr 2010
      • 347

      #3
      When I run that query I get a value of 0 in all fields. I know that this can't be right.

      here's the query I have:

      Code:
      Select 
      DateDiff(m, starttime, IsNull (endtime, starttime))
      From Exceptions2

      Comment

      • dougancil
        Contributor
        • Apr 2010
        • 347

        #4
        I figured this out .... here is the syntax that I have:

        Code:
        SELECT datediff(minute, starttime, endtime)  as duration from Exceptions2
        where exceptiondate between '5/1/2010' and '5/15/2010'

        Comment

        • gpl
          New Member
          • Jul 2007
          • 152

          #5
          Doug
          yup, you spotted the problem - mm means minute in time, but month in datediff and datepart

          sorry for the bum steer
          Graham

          Comment

          Working...