WithinPastYears indicates True if two TDateTime values are within the specified AYears number of years of each other.

WithinPastYears is used to determine whether the date specified by ANow is within AYears years of the date specified by AThen.

Fractional years do not count, so if ANow and AThen are two and a half years apart, calling WithinPastYears with AYears set to 2 returns True.

Declaration: function WithinPastYears(const ANow, AThen: TDateTime; const AYears: Integer): Boolean;

An example.

procedure OnMapEvent(var Value:Variant);
var
TheDate, ThatDate : TDateTime;
begin
//The IF is False as more than 10 years
TheDate := EncodeDateTime(2023, 11, 30, 13, 25, 15, 650);
ThatDate := EncodeDateTime(2012, 11, 29, 13, 25, 15, 650);
if WithinPastYears(ThatDate, TheDate, 10) then
LogInfo('The difference between the two dates is less than 10 years')
else
LogInfo('The difference between the two dates is more than 10 years');
end;