[futurebasic] Re: [FB] Date to week FN

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 1999 : Group Archive : Group : All Groups

From: Hans van Maanen <hvmaanen@...>
Date: Wed, 24 Feb 1999 22:41:14 +0100
>Mel & Carol Patrick wrote:
>
>> Anyone got a function that will take a date and return the week of the year
>> it resides in?
>>


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


Hope this still helps,

Hans van Maanen
Amsterdam