WithinPastMonths
WithinPastMonths indicates True if two TDateTime values are within the specified AMonths number of months of each other.
WithinPastMonths is used to determine whether the date specified by ANow is within AMonths months of the date specified by AThen.
Fractional months do not count, so if ANow and AThen are two and a half months apart, calling WithinPastMonths with AMonths set to 2, returns True.
Declaration: function WithinPastMonths(const ANow, AThen: TDateTime; const AMonths: Integer): Boolean;
An example.
procedure OnMapEvent(var Value:Variant);var TheDate, ThatDate : TDateTime;begin //The IF is False as more than 2 months TheDate := EncodeDateTime(2023, 11, 30, 13, 25, 15, 650); ThatDate := EncodeDateTime(2023, 03, 29, 13, 25, 15, 650); If WithinPastMonths(ThatDate, TheDate, 2) then LogInfo('The difference between the two dates is less than 2 months') else LogInfo('The difference between the two dates is more than 2 months'); //The IF is True as lsss than 2 months ThatDate := EncodeDateTime(2023, 10, 01, 13, 25, 15, 650); If WithinPastMonths(ThatDate, TheDate, 2) then LogInfo('The difference between the two dates is less than 2 months') else LogInfo('The difference between the two dates is more than 2 months');end;