How to find no of sunday after specific date in a month in s
how to find no of sunday after specific date in a month in sql
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 18, 2015, 1:44 AM EDT
Create Function NumberOfSundays(@dFrom datetime, @dTo datetime)
Returns int as
BEGIN
Declare @nSundays int
Set @nSundays = 0
While @dFrom <= @dTo Begin
If datepart(dw, @dFrom) = 1 Set @nSundays = @nSundays + 1
Set @dFrom = DateAdd(d, 1, @dFrom)
End
Return (@nSundays)
END
GO
-- Number of Sundays
Print dbo.NumberOfSundays()
-- Number of Other days
Print DateDiff(d, '2009/06/01', '2009/06/30') + 1 - dbo.NumberOfSundays('2009/06/01', '2009/06/30')