---
url: >-
  /statelake/scripting-reference/functions-and-procedures/datetime-functions/withinpastseconds.md
---

# WithinPastSeconds

**WithinPastSeconds** indicates **True** if two **TDateTime** values are within the specified **ASeconds** number of seconds of each other.

**WithinPastSeconds** is used to determine whether the date specified by **ANow** is within **ASeconds** seconds of the date specified by **AThen**.

Fractional seconds (milliseconds) do not count, so if **ANow** and **AThen** are two and a half seconds apart, calling **WithinPastSeconds** with **ASeconds** set to 2, returns **True**.

**Declaration**: function WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean;

A simple example follows.

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