Board index » delphi » Calculate week-number

Calculate week-number

Could anyone give the formula to calculate the number of the week given
a certain date.

I'm desperate ...

Thanks

 

Re:Calculate week-number


Quote
On Tue, 08 Jul 1997 14:39:30 +0300, BINAS <bi...@xs4all.nl> wrote:
>Could anyone give the formula to calculate the number of the week given
>a certain date.

The definition of week number varies from place to place.  By ISO
standards, weeks run Monday to Sunday.  For any given year, the first
week that includes a Thursday (the middle of the week) is numbered
week 1.  If there are any days in the year for the preceding week,
that is week 0.  

In contemporary American usage, weeks run Sunday to Saturday.  The
first week with a Sunday is week 1.

Another common usage is to let weeks run from whatever weekday 1 JAN
falls upon for 7 days.  This makes the weeknumber easy to compute
since it is the (ordinalday + 6) div 7.  

Re:Calculate week-number


One little (but important) correction:

Quote
J. W. Rider wrote:

. . . . .

Quote
> The definition of week number varies from place to place.  By ISO
> standards, weeks run Monday to Sunday.  For any given year, the first
> week that includes a Thursday (the middle of the week) is numbered
> week 1.  If there are any days in the year for the preceding week,
> that is week 0.

NO - they are part of week 52 or week 53 (as applicable) in the
previous year. Correspondingly, if December 28. 29. or 30 is a Sunday
then the remaining (max 3) days of the year are actually part of week 1
in the following year!.

A week number (according to ISO standards) calculation routine should
use the fact that January 4th is always within week 1, determine what
day in the week this date is, find the date for Monday in week 1 and
then calculate the actual week number. Finally if the calculated week
number is 53 it must check if the date belongs to week 1 in the next
year, and if the calculated week number is 0 it must recalculate the
week number as for December 31st in the previous year.

regards Sven

Other Threads