SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

SELECT GetDate() – 30 AS [This actually works??];

I just ran across this in a piece of code (that I didn’t write):

WHERE Thing >GETDATE()- 30

Aaaand it works. If you run the title of this blog post, you’ll get the date 30 days ago. I had no idea you could do this…I’m very much used to using DateAdd() for all my date manipulation needs.

The equivalent DateAdd() syntax, btw, would be


In a search for “GetDate() – 30″, the first link to come up is a tek-tips.com forum conversation with Denny Cherry (web, Twitter):

dateadd would be a better way to handle this.
dateadd(dd, -30, getdate()).  Check BOL for full syntax.

…there is little difference between them.  However dateadd is a handy function to know in case he later wants to go back by months, or years when getdate()-x doesn’t work.


Well, that mostly answers that, then.  Has anyone seen any performance issues or inconsistent behavior with this particular syntax?  I don’t intend to switch, I’m just interested in the variation on the language.


Share on TwitterShare on LinkedInShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit


Leave a comment on the original post [www.midnightdba.com, opens in a new window]

Loading comments...