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

# WithinPastDays

**WithinPastDays** indicates **True** if two **TDateTime** values are within the specified **ADays** number of days of each other.

**WithinPastDays** is used to determine whether the date specified by **ANow** is within **ADays** days of the date specified by **AThen**.

Fractional days do not count, so if **ANow** and **AThen** are two and a half days apart, calling **WithinPastDays** with **ADays** set to 2, returns **True**.

**Declaration**: function WithinPastDays(const ANow, AThen: TDateTime; const ADays: Integer): 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 days
  TheDate := EncodeDateTime(2023, 11, 30, 13, 25, 15, 650);
  ThatDate := EncodeDateTime(2023, 12, 02, 13, 25, 15, 700);
 If WithinPastDays(ThatDate, TheDate, 2) then
    LogInfo('The difference between the two dates is less than 2 days')
 else
    LogInfo('The difference between the two dates is more than 2 days');
end;
```
