Friday, May 7, 2010

T-SQL Query to Calculate Month End Date

Here is the easiest way to calculate Month End Date for any given date:

SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) + 1, 0)-1 AS MonthEndDate

Example:
If you replace GetDate() with any date, above query will return the Month End Date for that particular month.
If GetDate() value is '2010-01-25' then Output will be '2010-01-31'
If GetDate() value is '2010-02-20' then Output will be '2010-02-28'

1 comment:

  1. Now days it is easy

    SELECT EOMONTH(GETDATE())

    Pawan
    MSBISkills.com

    ReplyDelete

Here are few FREE resources you may find helpful.