Sunday, 25 March 2018

Get Month End Day and Date in sql server

Using sql script we will get the month day and date of any date.
SELECT datename(dw,DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) + 1, 0)-1) AS [Month End Day],
DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) + 1, 0)-1 AS [Month End Date]

See the output

Today date is 03/18/2018

Month-end day and date is below

If you want to get any particular date month you need to write the date in place of getdate() see below.

See it calendar

We will get the expected result using EOMONTH date function. See below
SELECT datename(dw,EOMONTH(GETDATE())) AS [Month End Day] ,
EOMONTH(GETDATE()) AS [Month End Date]


See the output below




Popular Posts