Wednesday, October 5, 2011

Get date of all Sundays in a given year - sql server


declare @d datetimeselect @d = '20100101'  --'20090101'  if you want 2009 etc etc
select dateadd(dd,number,@d) from master..spt_valueswhere type = 'p'
and year(dateadd(dd,number,@d))=year(@d)
and DATEPART(dw,dateadd(dd,number,@d)) = 1

No comments:

Post a Comment