How to determine week of quarter

  • Can someone help me with code that will give me the week number of each week of a quarter based on a date. For instance for April through June, there are 14 weeks.

    If I have an order date of 4/03/09, I need to return 'week 1'. If I have an order date of of 6/25/09, I need to return 'week 13'.

  • select

    DT,

    WeekOfQuarter=(datediff(dd,dateadd(QQ,datediff(QQ,0,DT),0),DT)/7)+1

    from

    ( -- Test Data

    select DT = convert(datetime,'20090403') union all

    select DT = convert(datetime,'20090625')

    ) a

    Results:

    DT WeekOfQuarter

    ------------------------------------------------------ -------------

    2009-04-03 00:00:00.000 1

    2009-06-25 00:00:00.000 13

    (2 row(s) affected)

Viewing 2 posts - 1 through 1 (of 1 total)

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