FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MATHEMATICS

Calculate the week number


Here is the corrected routine to calculate the week number according to the ISO rules. This I have tested...
WINDOW 1
TEXT _monaco,9
DO
  PRINT
  INPUT "Year?  "; year	'collect data
  LONG IF year > 0
    INPUT "Month? "; month
    INPUT "Day?   "; day
    IF year MOD 4 = 0 THEN leap = 1 ELSE leap = 0'is year a leap year?
    a = (year + INT(year/4) - leap + 1) MOD 7     'find weekday for Jan 1 (1 = Sat, 2 = Sun)
    m = 4 - a                                     'find date of Monday in first week
    d = day + INT(30.56 * month) - 32 + leap      'calculate day number
    IF month < 3 THEN d = d + 2                   'adjust for Jan and Feb
    w = INT((d - m) / 7) + 1                      'find number of whole weeks
    PRINT "Week no:" w
    wd = (d - m) MOD 7 + 1                        'remainder gives weekday
    PRINT "Weekday (1 = Mon, 2 = Tue):" wd
  END IF
UNTIL year = 0
END
Hans van Maanen