How to get the week numbers using kix?

We have a requirement that needs the week numbers.
Week 1 of the new year should be the first week that has 4 days in the new year. In 2006 that would be the week starting on Monday January 2nd. Next year it will be the week starting on Monday January 1st. At this time we are in week 22.

Is there an easy way to get these numbers using kix? I did a search and browsed the UDF forum but did not find anything coming close to this.

Dividing the number of days since 1-1 is a quick and dirty way to go but is not really reliable because it will only give the correct week number on Saturday (last Saturday was day 147 week 21 and next Saturday will be day 154 week 22) All other days this week will return 21 and only Saturday and Sunday will return 22.

Something like this would do in a quick and dirty way but is there a clean and nice way to do this?

Code:

$week = @YDAYNO / 7

Select
Case @DAY = "Monday"
$week = $week + 1
Case @DAY = "Tuesday"
$week = $week + 1
Case @DAY = "Wednesday"
$week = $week + 1
Case @DAY = "Thursday"
$week = $week + 1
Case @DAY = "Friday"
$week = $week + 1
Case @DAY = "Saturday"
;Do nothing week number is ok.
Case @DAY = "Sunday"
;Do nothing week number is ok.
EndSelect

?$week
Sleep 5



Edited by Mart (2006-05-29 04:17 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.