SQL Selecting the Last Day of a Month

I think SQL does a pretty good job with dates.  Here is a very simple way to get the last day of any month.  The example retreaves the last day of the last month.


SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

 

Replace the GETDATE() with whatever date you need to find the last day of the month before.

del.icio.us Digg StumbleUpon Facebook Google Bookmarks DZone
| View count: 375
blog comments powered by Disqus