supportlink (Week no. calculation)
Steve Huckvale
shuckvale@cosworth-racing.co.uk
Wed, 7 Jul 1999 10:06:35 +0100
Hi again Johan,
For what it's worth, here's the section of QUIZ code I wrote recently.
I'm sure there will be more elegant methods available to you though;
; --------------------------------------------------------------------
;
; *** ASSUMPTIONS ***
;
; Week 01 is the first *complete* week of a year, e.g. if the
; 4th of Jan 1999 is a Monday, then 1-3 Jan are week 52/1998
;
; Monday is considered the first day of a given week, Sunday
; is the last.
;
Def TEMPDAY = Mod(Days(DUEDATE),7)
Def DAYofWEEK = TEMPDAY - 1 if TEMPDAY > 0 else 6
;DAYofWEEK is the day of the week when DUEDATE falls (0=MON, 6=SUN)
Def ASC0101 char*8 = ascii(DUEDATE)[1:4] + "0101"
Def DATE0101 date = date(0,nconv(asc0101))
;DATE0101 holds the 01/01/YYYY - where YYYY is year in which DUEDATE falls
Def PREVMONDAY Date Format DDMMYY = &
Date(Days(DUEDATE)-(DAYofWEEK))
;PREVMONDAY is the Monday of the week in which DUEDATE falls.
Def OFFSET = Mod((Days(PREVMONDAY) - Days(DATE0101)),7)
Def FIRSTMONDAY Date Format DDMMYY = Date(Days(DATE0101) + OFFSET)
;FIRSTMONDAY is the first Monday of the calendar year in which DUEDATE
falls.
Def WEEKNUM Char*2 = &
"52" if PREVMONDAY < DATE0101 &
else Ascii((((days(PREVMONDAY)-days(FIRSTMONDAY)) / 7) + 1),2)
Def WEEKNOYEAR Char*7 = WEEKNUM + "/" + Ascii(FIRSTMONDAY)[1:4]
;
; --------------------------------------------------------------------
DUEDATE and WEEKNOYEAR are the key here, the latter being 7 chars for
display in the format ww/yyyy, representing the Week number in which
DUEDATE falls.
Steve Huckvale
Analyst Programmer
Cosworth Racing Limited
********************************************
* Any views or opinions stated above are my*
* own and should not be taken or implied to*
* represent those of my employer. *
********************************************
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
powerh-l@lists.swau.edu is gatewayed one-way to bit.listserv.powerh-l
This list is closed, thus to post to the list, you must be a subscriber.