To Calculate second sunday of th particular month

  • 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

  • Not challenging at all if you use a calendar table...

    http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html



    Clear Sky SQL
    My Blog[/url]

  • 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.

  • 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:

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply