WeekOf (WeekOfTheYear)
The WeekOf function returns the week of the year represented by the given date TDateTime value, as a number from 1 to 53.
WeekOf uses the ISO 8601 standard to define the week of the year, where a week is defined as running from Monday through Sunday, and the first week of the year is the one that includes the first Thursday of the year (the first week that includes four or more days in the year).
This means that if the first calendar day of the year is a Friday, Saturday, or Sunday, then for the first three, two, or one days of the calendar year, WeekOf returns the last week of the previous year.
Similarly, if the last calendar day of the year is a Monday, Tuesday, or Wednesday, then for the last one, two, or three days of the calendar year, WeekOf returns 1 (the first week of the next calendar year).
In 2023, the 1st January was a Sunday so this is not considered the first week of the 2023 year. This means that -
1st January 2023 is considered to be in the last week of 2022.
The week from 2 January to 8 January is the first week of 2023.
For 2023, the last calendar day of the year is Sunday 31st December. This means that -
31st December is considered to be the last week of the year.
Declaration: Function WeekOf( const AValue : TDateTime) : Word
Function WeekOfTheYear( const AValue : TDateTime) : Word
An example follows.
procedure
OnMapEvent(
var
Value:Variant);
begin
//If the date is 2023-11-28 then the result is 48
TheYear := WeekOf(Date);
LogInfo(
'The week number for today is '
+IntToStr(TheYear));
LogInfo(
''
);
end
;
WeekOf has the same functionality as the WeekOfTheYear function.