Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Struggling with a rolling week calculation

Status
Not open for further replies.

jmcg

Technical User
Jun 30, 2000
223
0
0
GB
I am trying to find a way to find out which week we are in based on a rolling period.
There is a choice of 2,3 or 4 week periods that the customer can select and I need to then work whether we are in week x of the period. To make matter worse the can all have a different start date.
Basically the start date could be 3 Dec 07 and a four week rolling period would make this week 4 of the second block of 4 (ie start was 8 weeks ago).
Or it could be 10 Dec 07 and a 2 week period and this would be week 1 of the 4 block.

Make sense! Struggling to think of a logical way to calculate this and would appreciate any pointers.
 
here's a broad strategy to get you started

find the difference in number of weeks between the start date and today

divide by the number of weeks in the period

the remainder is the week of the period you're in

so, for example, the difference between 3 Dec 07 and today is exactly 56 days, or 8 whole weeks, which gives 2 with 0 remainder when divided by 4

and then you have to add 1 because the starting day is included in the count

so, you see, today is actually the first day of the first week of the 3rd whole period

make sense?



r937.com | rudy.ca
 
Thanks r937
With a bit of messing about I got there, but would have been nowhere without your starter.
For anyone else here is the final code.
Code:
<CFSET GapWeeks = ((#now()# - #StartDate#))/7>
<CFSET RemoveWeeks = #int(#GapWeeks#  / #Weeks#)# * #Weeks#>
<CFSET WeekNum = #int((#GapWeeks# - #RemoveWeeks#)+1)#>
 
cleaning up your code...

<CFSET GapWeeks = (now() - StartDate) / 7 >
<CFSET RemoveWeeks = int(GapWeeks / Weeks) * Weeks >
<CFSET WeekNum = GapWeeks - RemoveWeeks + 1 >

also, i think you want to test this thoroughly, because i'm not sure you're adding the 1 in the right place

;-)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top