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
- Additional Training on my YouTube Channel
- Free SQL Query Training
- 70-461 exam preparation
More from Stedman Solutions:
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!