August 25, 2009 at 5:07 am
Hi Folks,
I have challenging task like to calculate the second sunday of the particular month...
ex data- month august second sunday is 9 LIKEWISE
can you please help me out with this task
Regards,
Leo Franklin.M
August 25, 2009 at 5:14 am
Not challenging at all if you use a calendar table...
August 25, 2009 at 6:55 am
Or set [date] to the first of the month desired and use
SET DATEFIRST 1
SELECT DATEADD(day,7+7-DATEPART(dw,[date]),[date])
Far away is close at hand in the images of elsewhere.
Anon.
August 26, 2009 at 1:59 am
Let say that the first Sunday of this year is 04/01/2009 ( date format is dd/mm/yyyy)
And the secondary you should have Tally Table ....you can find here http://www.sqlservercentral.com/articles/T-SQL/62867/
[/url]
After you create the Tally table use the code below and you will find your results:
SET DATEFORMAT dmy
DECLARE @curentDate datetime
SET @curentDate = '04/01/2009' --this is the first Sunday of this year!
SELECT N, dateadd(d, 14 * N , @curentDate) as DateSunday from Tally where N < 27
Stay tuned!
:ermm:
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply