07-25-2008, 01:14 AM
I could when I get time. The number of days is not hard to figure if you know if it is a leap year to add one to the days in February. You just count up to the month's days for each month previous to the month you are in and add the day number of the month you are in.
Then integer divide by 7.
For instance the 6th day of the year would = 6 \ 7 . So you are in the first week. If the date is the 8th of the year, that = 8 \ 7. The second week. Just add 1 to that and you have the week number.
Here is a SUB I made to return leap years and the first day of years weekday based on 1 being Sunday and 7 being Saturday. This could be used if you want to do it the ISO way. There are plenty of Leapyear routines that are simpler! Data is based on year 2000. Can go back or forward any years too:
Ted
Then integer divide by 7.
For instance the 6th day of the year would = 6 \ 7 . So you are in the first week. If the date is the 8th of the year, that = 8 \ 7. The second week. Just add 1 to that and you have the week number.
Here is a SUB I made to return leap years and the first day of years weekday based on 1 being Sunday and 7 being Saturday. This could be used if you want to do it the ISO way. There are plenty of Leapyear routines that are simpler! Data is based on year 2000. Can go back or forward any years too:
Code:
SUB LeapYear (yrn%, Leap$, firstday%) 'yrn% = year number from DATE$ or manual entry
Â
Leap$ = ""
LpYear% = 2000
firstday% = 7Â Â 'Â the first day of 2000 was a saturday, the 7th day
IF yrn% >= 2000 THENÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ' ** yrn% INPUT
  'FORWARD LOOP    2000 up
yrnm% = 1999Â Â 'start in 1999Â Â Â Â Â Â
DO
COLOR 14
 yrnm% = yrnm% + 1 ' start in 2000 (1999 + 1)
  IF yrnm% > 2000 THEN firstday% = firstday% + 1 'add one day every year to first day (52 weeks + 1
  IF firstday% > 7 THEN firstday% = firstday% - 7  ' ** firstday% OUTPUT
  IF yrnm% = LpYear% THEN Leap$ = "Y"        ' ** Lp$ for print only
  IF yrnm% MOD 100 = 0 THEN nly% = LpYear% MOD 400 'test century leap 400
  IF nly% <> 0 THEN Leap$ = "N"   ' if divisible by 400
  Â
  IF yrnm% - 1 = LpYear% THEN         ' add day AFTER leap year
   IF nly% = 0 THEN firstday% = firstday% + 1    ' add a leap day
   IF firstday% > 7 THEN firstday% = firstday% - 7
   Leap$ = "N"
   LpYear% = LpYear% + 4      ' find next leap year by adding 4
  END IF
  nly% = 0                     ' reset MOD value
LOOP UNTIL yrnm% = yrn%
END IFÂ Â Â Â Â Â Â Â Â Â Â 'end forward loop
IF yrn% < 2000 THENÂ Â Â Â 'REVERSE LOOPÂ Â 2000 down
Â
yrnm% = 2001Â Â Â Â Â Â Â Â 'start in 2001
DO
 yrnm% = yrnm% - 1            ' start in 2000 (2001 - 1)
  IF yrnm% < 2000 THEN firstday% = firstday% - 1 'subt one day every year to first day (52 weeks + 1
  IF firstday% = 0 THEN firstday% = 7
  IF yrnm% MOD 100 = 0 THEN nly% = LpYear% MOD 400 ' test century every 100
  Leap$ = "N"
  IF yrnm% = LpYear% THEN           ' BEFORE leap year
   IF nly% = 0 AND LpYear% <> 2000 THEN firstday% = firstday% - 1    ' subt a leap day
   IF firstday% = 0 THEN firstday% = 7
   LpYear% = LpYear% - 4            ' find next leap year
   Leap$ = "Y"
   IF nly% <> 0 THEN Leap$ = "N"   ' if divisible by 400
  END IF
  nly% = 0                   ' reset MOD value
LOOP UNTIL yrnm% = yrn%
END IF
END SUB
Ted
Get my QB demonstrator here: http://dl.dropbox.com/u/8440706/Q-Basics.zip