Finding Last Day of Current Month in SQL Server 2008

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 602
--SQL Server 2008
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) -- Last day of current month


Output:
2015-04-30 23:59:59.000

This is compatible with SQL Server 2008...

SQL Server 2012 introduced EOMONTH() function, we can find the last day of current month very easily in SQL Server.
--SQL Server 2012
SELECT EOMONTH(GETDATE()) LastDayInCurrentMonth
GO

LastDayInCurrentMonth
2015-04-30

Comments or Responses

Login to post response