March 26, 2015 Leave a Comment
The EOMONTH function returns the last day of a given month, or a future or past month by using the second parameter of offset. EOMONTH was introduced in SQL Server 2012, and is also available in SQL Server 2014 or newer.
Here is the sample code to go with the EOMONTH video tutorial:
-- EOMONTH (2012) DECLARE @date DATETIME SET @date = DATEFROMPARTS(2012, 11, 10) SELECT EOMONTH ( @date ) AS Result; -- next month end of month SELECT EOMONTH ( @date, 1) AS Result; -- last month end of month SELECT EOMONTH ( @date, -1) AS Result;