[futurebasic] Re: [FB] Date to week

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

From: Hans van Maanen <hvmaanen@...>
Date: Tue, 23 Feb 1999 08:10:37 +0100
Mel & Carol Patrick wrote:

> Anyone got a function that will take a date and return the week of the year
> it resides in?
>

This algorithm should work for dates from 1901 to 2099. I haven't yet
tested it thoroughly though, so check with some dates.
It uses the ISO way: first day of the week is Monday, first week is a week
with at least four days, i.e., it starts on Thursday or earlier.

'First find the leap year correction for the current year:

if year mod 4 = 0 then leap = 1 else leap = 0

'Next, the weekday of new year's day, 1-1-year:

a = (year + int(year / 4) - leap) mod 7

'Move to next Monday

m = a + 4

'Find the day number of the date you're looking for:

dayno = day + int(30.56 * month) - 32 + leap
if month < 3 then dayno = dayno + 2

'Find the number of whole weeks since the first Monday:

weekno = int(dayno / 7)

'And there you are...

Hope this helps. I'll write an FB routine to test it if I have time, but I
think this should do it.

Hans van Maanen
Science editor
'Het Parool'
Postbus 433
1000 AK Amsterdam
The Netherlands