Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compute week number.
#4
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:

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
Reply


Messages In This Thread
Compute week number. - by Moneo - 07-06-2008, 05:39 AM
Re: Compute week number. - by Clippy - 07-23-2008, 05:03 AM
Re: Compute week number. - by Moneo - 07-24-2008, 07:39 AM
Re: Compute week number. - by Clippy - 07-25-2008, 01:14 AM
Re: Compute week number. - by Moneo - 07-25-2008, 06:07 AM
Re: Compute week number. - by Clippy - 07-26-2008, 12:08 AM
Re: Compute week number. - by Moneo - 07-27-2008, 11:46 PM
Re: Compute week number. - by Clippy - 07-28-2008, 11:29 PM
Re: Compute week number. - by Moneo - 07-29-2008, 05:05 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)