Saturday, 25 July 2015

Count Sunday between two dates in sql and Count days in a month in sql

declare @d1 datetime, @d2 datetime select @d1 = '9/1/2014',@d2= '9/30/2014';with dates (date )as(select @d1 union all select dateadd(d,1,date) from dates where date < @d2 )select date from dates where  datename(dw,date) = 'Sunday'

SELECT DAY(DATEADD(DD,-1,DATEADD(MM,DATEDIFF(MM,-1,'2/4/2015'),0)))

No comments:

Post a Comment