T-SQL Tutorial

T-SQL EOMONTH Date Function


Eonmonth is an date function and returns the last day of the month that contains the specified date, with an optional offset.

EOMONTH Syntax:

EOMONTH ( date_expression [, add_month ] )

EOMONTH Example:

DECLARE @lastday DATETIME = '02/22/2014';
SELECT EOMONTH ( @lastday ) AS Result;

Result
2014-02-28

SELECT EOMONTH ( GETDATE() ) as 'This_Month',
EOMONTH ( GETDATE(), 1 ) as 'Next_Month',
EOMONTH ( GETDATE(), -1 ) as 'Last_Month';

This_MonthNext_MonthLast_Month
2014-02-282014-03-312014-01-31