Search

Showing posts with label First and Last Saturday of Each Month. Show all posts
Showing posts with label First and Last Saturday of Each Month. Show all posts

Tuesday, July 12, 2011

Get First and Last Saturday of Each Month


declare @year int
set @year =2011
-- First and Last Sunday by SqlServerCurry.com
select min(dates) as first_saturday,max(dates) as last_saturday 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
DATEDIFF(day,DATEADD(year,@year-1900,0),DATEADD(year,@year-1900+1,0))
) as t where DATENAME(weekday,dates)='saturday'
group by DATEADD(month,datediff(month,0,dates),0)