Get End of Month
-
Posted on December 6, 2009 by Derek Dieter
-
0
The following short code will return the date and time for the very end of the month passed in. It works by first getting the beginning of the month for the date passed in, adding one month to that date, then subtracting 3 milliseconds. This gives the latest possible date for the end of the month as the DateTime data type has a granularity of 3 milliseconds.
[cc lang=”sql”]
DECLARE @DateIn datetime
SET @DateIn = GETDATE()
SELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,@DateIn)+1,0)))
[/cc]
Post a comment
- Comments (RSS)
- Trackback
- Permalink