EncodeDayOfWeekInMonth
The reverse of DecodeDayOfWeekInMonth , this EncodeDayOfWeekInMonth function returns a TDateTime that represents a specified instance of a day ADayOfWeek, of 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 definition for 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.
ANthDayOfWeek is the occurrence of the specified day of the week that is specified by ADayOfWeek, and can be a number from 1 to 5 inclusive, indicating the week within the specified month.
If a month does not include 5 Mondays, setting ANthDayOfWeek to 5 and ADayOfWeek to 1 causes EncodeDayOfWeekInMonth to raise an exception error.
ADayOfWeek is the day of the week, where 1 is Monday, 2 is Tuesday e.t.c., with 7 representing Sunday.
Declaration: function EncodeDayOfWeekInMonth(const AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word): TDateTime;
procedure
OnMapEvent(
var
Value:Variant);
var
aYear, aMonth, aNth, aDay :
word
;
begin
aYear :=
2024
;
aMonth :=
5
aNth :=
2
;
aDay :=
5
;
//Create a date/time from its separate parts - returns 10-05-2024 00:00:00:0000
LogInfo(FormatDateTime(
'dd-mm-yyyy hh:nn:ss.zzz'
,EncodeDayOfWeekInMonth(aYear, aMonth, aNth, aDay)));
LogInfo(
''
);
end
;