To list all sundays between two dates /*Example for datediff : getting no of days passed since 01-01-2004*/ declare @datevar datetime declare @t int declare @day varchar(20) set @datevar = '1/1/2008' set @t = datediff(dd,@datevar,getdate())-- [No of days since 01-01-2004] declare @cnt int set @cnt = 0 while @T > @cnt begin set @day = DATENAME(dw, getdate() - @cnt) if @day = 'Sunday' begin select getdate() - @cnt as Sundays end set @cnt = @cnt + 1 end
You might want to specify the language that is written in. Why are you posting that in this forum? Is that related to databases?