HoursBetween
HoursBetween returns the number of hours between two specified TDateTime values.
Fractional or part hours are not counted, so the function will return a whole integer value only.
For example, HoursBetween reports the difference between 10:00 A.M. and 10:59:59 A.M. on the same day as zero (0) hours between, because the hour stops a second short of an entire hour.
The ordering of the two dates doesn't matter - the number of hours will not be negative.
Declaration: Function HoursBetween(const ANow, AThen: TDateTime): Int64;
A simple example follows.
procedure
OnMapEvent(
var
Value:Variant);
var
TheDate, ThatDate : TDateTime;
NumBetw :
integer
;
begin
//Result is 0 hours
TheDate := EncodeDateTime(
2023
,
02
,
13
,
10
,
00
,
00
,
000
);
ThatDate := EncodeDateTime(
2023
,
02
,
13
,
10
,
59
,
59
,
000
);
NumBetw := HoursBetween(TheDate,ThatDate);
LogInfo(
'The number of hours between these dates is - '
+IntToStr(NumBetw));
//Result is 1 hour
ThatDate := EncodeDateTime(
2023
,
02
,
13
,
11
,
00
,
00
,
000
);
NumBetw := HoursBetween(TheDate,ThatDate);
LogInfo(
'The number of hours between these dates is - '
+IntToStr(NumBetw));
end
;