Find first and last sunday

Posted on: February 17, 2011 Posted by: JJ Comments: 0

Find first and last sunday

This is a nifty query that I can use on reporting, I’m sure there are other uses for it.


declare @year int
set @year =2011

— First and Last Sunday by
select min(dates) as first_sunday,max(dates) as last_sunday from
select dateadd(day,number-1,DATEADD(year,@year-1900,0))
as dates from master..spt_values
where type=’p’ and number between 1 and
) as t
where DATENAME(weekday,dates)=’sunday’
group by DATEADD(month,datediff(month,0,dates),0)