SQL server Denali features: EOMONTH()

Oopps! Upgrade your browser pretty please.Oopps! Upgrade your browser pretty please.

In the next version of SQL server, codename Danli, there is a new function called EOMONTH(). You can use the function to get the last day of month for the month you specify.

The code below will return the last day of Februari: DECLARE @date DATETIME; SET @date = ‘1971-02-08’; SELECT EOMONTH ( @date ) AS Result; You can actually specify an offset to get for example the end of previous month: DECLARE @date DATETIME; SET @date = ‘1971-02-08’; SELECT EOMONTH ( @date, -1 ) AS Result; If you are not planning to upgrade when Denali is released you can still use the DATEADD function to calculate the previous month: DECLARE @date DATETIME; SET @date = ‘1971-02-08’; SELECT DATEADD(d, 0-day(@date),@date)

If you want to know more about SQL server, feel free to contact one of our SQL server consultants and we will try to help you.