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

# WeeksBetween

**WeeksBetween** returns the approximate number of weeks between two specified **TDateTime** values.

Fractional weeks are not counted, so the function will return a whole integer value only.

For example, **WeeksBetween** reports the difference between 12:00 A.M. on 13th February and 11:59 P.M. on 19th February as zero(0), because it is one (1) minute short of a full week.

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

**Declaration**: Function WeeksBetween(const ANow, AThen: TDateTime): Integer;

Examples follow.

```pascal
procedure OnMapEvent(var Value:Variant);
var
  TheDate, ThatDate : TDateTime;
  NumBetw : integer;
begin
 //Result is zero (as above)
  TheDate := EncodeDateTime(2023, 02, 13, 00, 00, 00, 000);
  ThatDate := EncodeDateTime(2023, 02, 19, 23, 59, 00, 000);
  NumBetw := WeeksBetween(TheDate,ThatDate);
  LogInfo('The number of weeks between these dates is - '+IntToStr(NumBetw));

 //Result is 1
  ThatDate := EncodeDateTime(2023, 02, 20, 00, 00, 00, 000);
  NumBetw := WeeksBetween(TheDate,ThatDate);
  LogInfo('The number of weeks between these dates is - '+IntToStr(NumBetw));

end;
```
