WeekNumber

delphimoon

WeekNumber

Algorithms

Top  Previous  Next

 

Calculates the number of the week for the given date

 

function WeekNumber(date:TDateTime): integer;

 

Description

Calculates the number of the week for the given date. According to the international standard ISO 8601 the week starts with Monday, and the first week of a year is that which has the majority of days in the new year, i.e. the one which contains the first Thursday.

 

Hint

This algorithm is only calculating the week number according to the ISO standard, however there are many other local standards for the week counting - for example in many cultures the week is considered to begin on Sunday. So when you need a week number calculation make sure which standard you'll need.

 

Note

Starting with Delphi 6 the VCL contains the function WeekOf which does the same as this one.