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

# SecondsBetween

**SecondsBetween** returns the number of seconds between two specified **TDateTime** values.

Fractional or part seconds (milliseconds) are not counted, so the function will return a whole integer value only.

For example, **SecondsBetween** reports the difference between 10:00 A.M. and 10:00:00:999 A.M. on the same day as zero (0) seconds between, because the **TDateTime** value stops a millisecond short of an entire second.

The ordering of the two dates doesn't matter - the number of seconds will not be negative.

**Declaration**: Function SecondsBetween(const ANow, AThen: TDateTime): Int64;

A simple example follows.

```pascal
procedure OnMapEvent(var Value:Variant);
var
  TheDate, ThatDate : TDateTime;
  NumBetw : integer;
begin
 //Result is 0 seconds
  TheDate := EncodeDateTime(2023, 02, 13, 10, 00, 00, 000);
  ThatDate := EncodeDateTime(2023, 02, 13, 10, 00, 00, 999);
  NumBetw := SecondsBetween(TheDate,ThatDate);
  LogInfo('The number of seconds between these dates is - '+IntToStr(NumBetw));

 //Result is 1 second
  ThatDate := EncodeDateTime(2023, 02, 13, 10, 00, 01, 000);
  NumBetw := SecondsBetween(TheDate,ThatDate);
  LogInfo('The number of seconds between these dates is - '+IntToStr(NumBetw));

 //Result is 59 seconds
  ThatDate := EncodeDateTime(2023, 02, 13, 10, 00, 59, 000);
  NumBetw := SecondsBetween(TheDate,ThatDate);
  LogInfo('The number of seconds between these dates is - '+IntToStr(NumBetw));

end;
```
