WeekSpan returns the approximate number of weeks between two specified TDateTime values, including the fraction of those weeks.

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

If you want a function that only returns a full number of weeks as an integer with no fraction, please review WeeksBetween.

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

Declaration: Function WeekSpan(const ANow, AThen: TDateTime): Double;

Examples follow.

procedure OnMapEvent(var Value:Variant);
var
TheDate, ThatDate : TDateTime;
NumBetw : double;
begin
//Result is 0.99990079365047
TheDate := EncodeDateTime(2023, 02, 13, 00, 00, 00, 000);
ThatDate := EncodeDateTime(2023, 02, 19, 23, 59, 00, 000);
NumBetw := WeekSpan(TheDate,ThatDate);
LogInfo('The number of weeks between these dates is - '+FloatToStr(NumBetw));
 
//Result is 1.0
ThatDate := EncodeDateTime(2023, 02, 20, 00, 00, 00, 000);
NumBetw := WeekSpan(TheDate,ThatDate);
LogInfo('The number of weeks between these dates is - '+FloatToStr(NumBetw));
end;