Skip to content
 

Get End of Month

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.

DECLARE @DateIn datetime

SET @DateIn = GETDATE()

SELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,@DateIn)+1,0)))
Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Related Posts:

  • » SQL Server Add Primary Key
  • » SQL Server Select
  • » Compare Stored Procedure Dataset Output
  • » Beginning of Month
  • » Create Index on Table Variable
    blog comments powered by Disqus