DaySpan returns the number of days between two specified TDateTime values.

DaySpan differs from the function DaysBetween, in that DaySpan returns fractional or part days.

For example, DaySpan reports the difference between 1st February 11:59 PM and 2nd February 11:58 PM as 0.999305555560568 days span, because the day stops a second short of an entire day.

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

Declaration: Function DaySpan(const ANow: TDateTime; const AThen: TDateTime): Double;

Examples follow.

procedure OnMapEvent(var Value:Variant);
var
vYear, vDate, vTween, vTween2 : TDateTime;
vStrYear, vStrDate : string;
vBetwix : double;
begin
//Result is 4.0 days
vBetwix := DaySpan(Date, Date+4);
LogInfo(FloatToStr(vBetwix));
 
//Result is 2.0 days
vStrDate := '01-10-2023';
vStrYear := '03-10-2023';
vDate := StringToDateTime('dd/mm/yyyy',vStrDate);
vYear := StringToDateTime('dd/mm/yyyy',vStrYear);
vBetwix := DaySpan(vDate, vYear);
LogInfo(FloatToStr(vBetwix));
 
//Result is 0.999305555560568 days - 1 second short of a day
vTween := EncodeDateTime(2023, 10, 01, 23, 59, 59, 999);
vTween2 := EncodeDateTime(2023, 10, 02, 23, 58, 59, 999);
LogInfo(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', vTween));
LogInfo(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', vTween2));
vBetwix := DaySpan(vTween, vTween2);
LogInfo(FloatToStr(vBetwix));
 
//Result is 1.0 day - seconds match
vTween := EncodeDateTime(2023, 10, 01, 23, 59, 59, 999);
vTween2 := EncodeDateTime(2023, 10, 02, 23, 59, 59, 999);
LogInfo(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', vTween));
LogInfo(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', vTween2));
vBetwix := DaySpan(vTween, vTween2);
LogInfo(FloatToStr(vBetwix));
 
end;