Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
This function returns the last day of the month containing a specified date, with an optional offset.
Tip
In SQL Server 2022 (16.x) and later versions, you can use DATETRUNC to calculate the start of the month.
Transact-SQL syntax conventions
EOMONTH ( start_date [ , month_to_add ] )
A date expression that specifies the date for which to return the last day of the month.
An optional integer expression that specifies the number of months to add to start_date.
If the month_to_add argument has a value, then EOMONTH
adds the specified number of months to start_date, and then returns the last day of the month for the resulting date. If this addition overflows the valid range of dates, then EOMONTH
raises an error.
date
The EOMONTH
function can remote to instances running SQL Server 2012 (11.x) and later versions. It can't remote to instances with a version before SQL Server 2012 (11.x).
DECLARE @date DATETIME = '12/1/2024';
SELECT EOMONTH(@date) AS Result;
GO
Here's the result set.
Result
------------
2024-12-31
DECLARE @date VARCHAR(255) = '12/1/2024';
SELECT EOMONTH(@date) AS Result;
GO
Here's the result set.
Result
------------
2024-12-31
The values shown in these result sets reflect an execution date between and including 12/01/2024
and 12/31/2024
.
DECLARE @date DATETIME = '2024-12-31';
SELECT EOMONTH(@date) AS 'This Month';
SELECT EOMONTH(@date, 1) AS 'Next Month';
SELECT EOMONTH(@date, -1) AS 'Last Month';
GO
Here's the result set.
This Month
-----------------------
2024-12-31
Next Month
-----------------------
2025-01-31
Last Month
-----------------------
2024-11-30
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today