469,097 Members | 1,599 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

How to get the Datediff between two fields

347 100+
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
Nov 1 '10 #1

✓ answered by dougancil

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

Expand|Select|Wrap|Line Numbers
  1. SELECT datediff(minute, starttime, endtime)  as duration from Exceptions2
  2. where exceptiondate between '5/1/2010' and '5/15/2010'
  3.  

4 3354
gpl
152 100+
Books online gives you the syntax
its along the lines of
Expand|Select|Wrap|Line Numbers
  1. Select 
  2. DateDiff(mm, starttime, IsNull(endtime, starttime))
  3. From Exceptions
Nov 2 '10 #2
dougancil
347 100+
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:

Expand|Select|Wrap|Line Numbers
  1. Select 
  2. DateDiff(m, starttime, IsNull (endtime, starttime))
  3. From Exceptions2
  4.  
Nov 2 '10 #3
dougancil
347 100+
I figured this out .... here is the syntax that I have:

Expand|Select|Wrap|Line Numbers
  1. SELECT datediff(minute, starttime, endtime)  as duration from Exceptions2
  2. where exceptiondate between '5/1/2010' and '5/15/2010'
  3.  
Nov 2 '10 #4
gpl
152 100+
Doug
yup, you spotted the problem - mm means minute in time, but month in datediff and datepart

sorry for the bum steer
Graham
Nov 2 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Paolo | last post: by
1 post views Thread by Miguelito Bain | last post: by
3 posts views Thread by T23Ij9 | last post: by
1 post views Thread by John T. | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.