question

minijebu avatar image
minijebu asked

How to use DateDiff() with constant value as parameter?

In DateDiff(MM,0,GetDate()),does 0 indicate 01/01/1900? And in DateDiff(MM,-1,GetDate()),what do -1 stand for? does 0 and -1 are the only values ,used like this?
datediff
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered
Yes. The zero reflects 1/1/1900 and the -1 reflects 12/31/1899, which is one day less than 1/1/1900. You can use any integer value as the start date. This, I believe, will reflect the number of days plus or minus from 1/1/1900 DECLARE @dte DATETIME = '1/1/1900' SELECT DATEDIFF(MM,0,GetDate()) -- 1388 SELECT DATEDIFF(MM,'1/1/1900',GETDATE()) -- 1388 SELECT DATEDIFF(MM,'12/1/1899',GetDate()) -- 1389 SELECT DATEDIFF(MM,32,GETDATE()) -- 1389 SELECT DATEDIFF(MM, @dte + 32,GETDATE()) -- 1387 SELECT @dte + 32 SELECT DATEDIFF(MM, '1900-02-02',GETDATE()) -- 1387 Hope that helps!
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

minijebu avatar image minijebu commented ·
Thanks JohnM
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.