A new function is introduced in SQL Server Denali
CTP3, 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.
SELECT EOMONTH (GETDATE()) AS Result;
Or you can add number months to get last date.
SELECT EOMONTH (GETDATE(),3) AS Result;
------------------------------------------------------------------------------------
Read More about SQL Server 2012 (Code Name: Denali)
No comments:
Post a Comment
All suggestions are welcome