EncodeDateMonthWeek expands upon the function EncodeDateWeek.

This function returns a TDateTime that represents a specified day ADayOfWeek, of a specified week AWeekOfMonth, in a specified month AMonth, in a specified year AYear.

The time portion of the return value is 00:00:00 - midnight at the start of the specified day ADayOfWeek.

The definitions for AWeekOfMonth and ADayOfWeek follow the ISO 8601 standard.

  • AYear is the year which can be any value from 1 through 9999 inclusive.

  • AMonth can be any month value from 1 through to 12 inclusive.

  • AWeekOfMonth is the week within AMonth, where 1 is the first week that includes four or more days.

    • If the first calendar day of the month is a Friday, Saturday, or Sunday, then those three days must be expressed using AMonth set to the previous month, and AWeekOfMonth must be set to the number of weeks in the previous month.

    • Similarly, if the last calendar day of the month is a Monday, Tuesday, or Wednesday, then those three days are expressed with AMonth set to the following month and AWeekOfMonth is set to 1.

  • ADayOfWeek is the day of the week, where 1 is Monday, 2 is Tuesday e.t.c., with 7 representing Sunday.

If any of the specified parameters are not within range, EncodeDateMonthWeek will raise an error.

Declaration: function EncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word): TDateTime;

procedure OnMapEvent(var Value:Variant);
var
aYear, aMonth, aWeek, aDay : word;
begin
aYear := 2024;
aMonth := 5
aWeek := 2;
aDay := 5;
//Create a date/time from its separate parts - returns 10-05-2024
LogInfo(FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz',EncodeDateMonthWeek(aYear, aMonth, aWeek, aDay)));
LogInfo('');
 
end;