Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to determine week of quarter Expand / Collapse
Author
Message
Posted Monday, August 24, 2009 10:26 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 24, 2009 12:08 PM
Points: 3, Visits: 7
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'.
Post #776148
Posted Monday, August 24, 2009 10:44 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 6:27 PM
Points: 3,135, Visits: 11,479
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)

Post #776161
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse