Menu

Wednesday 20 February 2013

New features in SQL Server 2012

EOMONTH(): Returns the last day for a specified month


Syntax: 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.

SELECT EOMONTH (GETDATE()) AS 'Last day of This Month';
--Output:
Last day of This Month
----------------------
2013-02-28

SELECT EOMONTH (GETDATE(),1 ) AS 'Last day of Next Month';
--Output:
Last day of Next Month
----------------------
2013-03-31

SELECT EOMONTH (GETDATE(),-1 ) AS 'Last day of Last Month';
--Output:
Last day of Last Month
----------------------
2013-01-31


<<LAG()                                                           Go To Main Page

No comments:

Post a Comment