SQL DATEDIFF Not working!?

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-03-25T16:57:22Z Indexed on 2010/03/25 17:03 UTC
Read the original article Hit count: 581

Filed under:
|
|

Hi all,

I am running a simple DATEDIFF query but it doesn't seem to calculate the days properly or i'm doing something wrong.

If I run

PRINT DATEDIFF(Day, 2010-01-20, 2010-01-01)
RETURN 19

Which is correct. If i change the month in the first date to Feb (02) I get something strange.

PRINT DATEDIFF(Day, 2010-02-20, 2010-01-01)
RETURN 20

Now shouldn't it be 48 or something?

Can anyone see what i'm doing wrong or is this not the correct function to be using if I want the No of days between these dates?

I've tried taking one date from the other:

PRINT (2010-02-20) - (2010-01-01)
RETURN -20

Any help much appreciated.

Thanks J.

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql