Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

EOMONTH (Transact-SQL)

Applies To: SQL Server 2014, SQL Server 2016 Preview

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

Returns the last day of the month that contains the specified date, with an optional offset.

Topic link icon Transact-SQL Syntax Conventions

Applies to: SQL Server (SQL Server 2012 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.

EOMONTH ( start_date [, month_to_add ] )

start_date

Date expression specifying the date for which to return the last day of the month.

month_to_add

Optional integer expression specifying the number of months to add to start_date.

If this argument is specified, 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 an error is raised.

This function can be remoted to SQL Server 2012 servers and higher. It cannot be remoted to servers with a version lower than SQL Server 2012.

A. EOMONTH with explicit datetime type

DECLARE @date DATETIME = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO

Here is the result set.

Result
------------
2011-12-31

(1 row(s) affected)

B. EOMONTH with string parameter and implicit conversion

DECLARE @date VARCHAR(255) = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO

Here is the result set.

Result
------------
2011-12-31

(1 row(s) affected)

C. EOMONTH with and without the month_to_add parameter

DECLARE @date DATETIME = GETDATE();
SELECT EOMONTH ( @date ) AS 'This Month';
SELECT EOMONTH ( @date, 1 ) AS 'Next Month';
SELECT EOMONTH ( @date, -1 ) AS 'Last Month';
GO

Here is the result set.

This Month
-----------------------
2011-12-31

(1 row(s) affected)

Next Month
-----------------------
2012-01-31

(1 row(s) affected)

Last Month
-----------------------
2011-11-30

(1 row(s) affected)

Community Additions

ADD
Show:
© 2015 Microsoft