SQL Server 2012 – EOMONTH – Find Last Day of Any Month

In SQL Server 2012, seven new datetime functions have been introduced. EOMONTH is one of them.  This is really useful function because many times we need to find the last date of month.

Syntax:

EOMONTH ( start_date [, month_to_add ] )

Find Last Day of Current Month

Example:

SELECT EOMONTH (GETDATE()) Last_Date_Month

Result:

Date
————–
2012-04-30

Find Last Day of Next Month

Example:

SELECT EOMONTH (GETDATE(),1) Last_Date_Next_Month

Result:

Date
————–
2012-05-31

Find Last Day of Previous Month

Example:

SELECT EOMONTH (GETDATE(),-1) Last_Date_Previous_Month

Result:

Date
————–
2012-03-31

One can also refer the alternative

http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/