Friday, September 16, 2011

SQL Server Denali: Get Last Date of Month

In SQL Server Denali CTP3 a new function is introduced, though which you can easily find out last date of any month. Prior to this we were using different methods to get last date of month. Following one, I like most.
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GetDate())+1,0))
But now it’s more easy with EOMONTH() function. Just provide a date in DateTime format or in string format and it will return last date of required month.
Or you can add number months to get last date.

No comments:

Post a Comment