hillman
Posts: 25 Joined: Mon Apr 08, 2002 9:06 am
Post
by hillman » Thu Dec 14, 2006 10:01 am
Is there an easy way in Vortex to calculate the first and last days of a given week (number). For example, if I know that the current week is week no. 50, how can I calculate that Monday is the 11th December and Friday is the 15th?
(The other way around is easy enough, but I can't figure how to arrive at a timestamp from just the week number...)
John
Site Admin
Posts: 2622 Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:
Post
by John » Thu Dec 14, 2006 11:03 am
The easiest way is probably to use calrule to generate likely dates, e.g. something like
<strfmt %at "%Y-01-01" now>
<$startofyear=$ret>
<calrule RULE="every Monday" START=$startofyear SKIP=50 MAX=2>
<$Monday=$ret>
<$weekno=(week($Monday))>
<if $weekno eq 50>
<$Friday=($Monday + (4 * 86400))>
<break>
</if>
</calrule>
John Turnbull
Thunderstone Software
hillman
Posts: 25 Joined: Mon Apr 08, 2002 9:06 am
Post
by hillman » Wed Dec 20, 2006 5:27 am
Thanks for your help John, but when I try that I get:
Invalid calendar rule syntax `every Monday' in the function vx_calrulenext
We're running version 5.1.11 so I think it should work?
hillman
Posts: 25 Joined: Mon Apr 08, 2002 9:06 am
Post
by hillman » Wed Dec 20, 2006 11:04 am
I wrote my own function which does it the hard way!
(It might not be the most elegant method, but it works, so I'll post it incase anyone else is searching for this).
<!-- START OF CURRENT YEAR -->
<strfmt %at "%Y-01-01" now>
<$startyear = (convert($ret, 'date'))>
<!-- GET FIRST DAY AS NUMERIC -->
<strfmt %at "%w" $startyear>
<$firstday=$ret>
<!-- FIND THE FRIDAY PRECEEDING THE FIRST SUNDAY -->
<$offset = (-2 - $firstday)>
<!-- ADD THE CURRENT WEEK OFFSET -->
<strfmt %at "%U" now>
<$currentweek=(-1 + $ret)>
<$offset = ($offset + ($currentweek * 7))>
<!-- TIMES OFFSET BY NO OF SECONDS -->
<$secs = ($offset * 86400)>
<!-- RESULTS -->
<$lastfriday = ($startyear + $secs)>
<$nextthursday = ($lastfriday + (6 * 86400))>
(This version calculates the previous Friday and the following Thursday of the current week, simple because that's the date range we use, but could easily be ammended to do Mon-Fri or Mon-Sun etc)...
mark
Site Admin
Posts: 5519 Joined: Tue Apr 25, 2000 6:56 pm
Post
by mark » Wed Dec 20, 2006 12:01 pm
This will give the previous friday and it's following thursday.
<$Friday=(convert( '-friday' , 'date' ))>Friday=$Friday
<$Thursday=($Friday + (6 * 86400))>Thursday=$Thursday