Appearance
DecodeDayOfWeekInMonth
For a given TDateTime value AValue, DecodeDayOfWeekInMonth returns the day of the week and, for that day of the week, which occurrence it is within the month.
AValue is the date/time TDateTime value about which you want information.
AYear returns the year that AValue represents.
AMonth returns the month in which AValue occurs. This value can be from 1 through 12, inclusive.
ANthDayOfWeek indicates the count for the day of the week represented by AValue.
- If AValue represents the second Tuesday of the month, ANthDayOfWeek returns 2. DecodeDayOfWeekInMonth counts every occurrence of the given weekday, so if AValue represents a Saturday that is the first day of a month, DecodeDayOfWeekInMonth returns 1 as the value of ANthDayOfWeek.
ADayOfWeek returns the day of the week that AValue represents, where 1 Monday and 7 is Sunday.
The definition for ADayOfWeek follows the ISO 8601 standard.
Declaration: procedure DecodeDayOfWeekInMonth(const AValue: TDateTime; out AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word);
An easy example follows.
pascal
procedure ScriptEvent(var Value:Variant);
var
aDate : TDateTime;
aYear, aMonth, aNth, aDay : word;
begin
//Where NOW is Wednesday 06-12-2023 - result is 2023, 12, 1, 3
ADate := Now;
DecodeDayOfWeekInMonth(aDate, aYear, aMonth, aNth, aDay);
LogInfo('Year is - '+IntToStr(aYear));
LogInfo('Month is - '+IntToStr(aMonth));
LogInfo('Nth is - '+IntToStr(aNth));
LogInfo('Day is - '+IntToStr(aDay));
end;
