How to get last date of a Month in Sql Server

April 15, 2009

declare @date varchar(10)

set @date=convert(varchar,year(getdate()))+’-'+convert(varchar,(month(getdate())+1))+’-01′

select dateadd(day,-1,@date)

Logic is which month we want to find the last date take that month.

Suppose i want to find last day of   14-04-2009

Add 1 month to this and create a format of next month first day

the next month will be 05 ,2009

2009-05-01

With dateadd function add -1 day to that function . So it will come to the previous month last day.

dateadd(day,-1,’2009-05-01′)

it will display   ‘2009-04-31