March 4, 2009 at 1:05 pm
souLTower (3/4/2009)
Gail, I'm confused as to why to use the datediff function.
The dateadd/datediff is a trick to 'truncate' a data to a certain precision (day, week, month, year)
In the one I used above
datediff(mm,0, Getdate()) will get the number of months since the 0 date. For today, that will evaluate to 1310.
Then I use dateadd, with the same interval to add that number of months back on to the 0 date and in essence to 'truncate' the original date to the beginning of the given interval (in this case today's date and the interval of month, returning the beginning of the current month.)
This works with the yy interval to get the beginning of the year, it works with qq, getting the beginning of the quarter. It works with mm, getting the beginning of the month, it works with dd getting the begininng of the day (the most useful, as it removes the time from the date).
I think it works will hh, getting the beginning of the hour, but it does not work with minute or second.
Any clearer?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 4, 2009 at 1:09 pm
Ah, very cool indeed.
Thanks
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply