Using The TSQL EOMONTH Function

Download PDF

Here is a quick video training on how to use the T-SQL EOMONTH function on SQL Server. This was originally part of my free SQL query training for the 70-461 certification exam.

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;

See Also

Posted in 70-461 Training, TSQL 2012 Tagged with: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.