End of month : Dateadd with Datepart MONTHPosted: January 15, 2015
If datepart is month and the date month has more days than the return
month and the date day does not exist in the return month, the last day of the return month is returned.
Here is a sample to get month end date within a year:
;with mycte as ( select 1 as n, dateadd(year, datediff(year,0,getdate()), 0) as Firstdt,EOMONTH(dateadd(year, datediff(year,0,getdate()), 0) ) as Enddt1 union all Select n+1 as n, Firstdt, EOMONTH(dateadd(month,n,Firstdt)) Enddt1 from mycte where n<12 ) select n as monthNum,Enddt1 from mycte order by Enddt1