Skip to content

WithinPastHours ​

WithinPastHours indicates True if two TDateTime values are within the specified AHours number of hours of each other.

WithinPastHours is used to determine whether the date specified by ANow is within AHours hours of the date specified by AThen.

Fractional hours do not count, so if ANow and AThen are two and a half hours apart, calling WithinPastHours with AHours set to 2, returns True.

Declaration: function WithinPastHours(const ANow, AThen: TDateTime; const AHours: Int64): Boolean;

An example follows.

pascal
procedure OnMapEvent(var Value:Variant);
var
  TheDate, ThatDate : TDateTime;
begin
 //The IF is True as less than or equal to 2 hours
  TheDate := EncodeDateTime(2023, 11, 30, 13, 25, 15, 650);
  ThatDate := EncodeDateTime(2023, 11, 30, 14, 25, 15, 700);
 If WithinPastHours(ThatDate, TheDate, 2) then
    LogInfo('The difference between the two dates is less than 2 hours')
 else
    LogInfo('The difference between the two dates is more than 2 hours');
end;