Page 1 of 1 1
Topic Options
#162592 - 2006-05-29 04:07 PM Getting the correct weeknumber
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
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.

Top
#162593 - 2006-05-30 09:31 AM Re: Getting the correct weeknumber
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Have a look at my date format udf http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=83494&an=&page=0&vc=1

It returns a load of different values, including week number.

NB "week number" is one of the elements that requires the SerialDate() UDF for calculations.

Top
#162594 - 2006-05-30 09:44 AM Re: Getting the correct weeknumber
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Thanx Richard.
By feeding it the @date macro it works just fine.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.063 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org