A more general solution:
Var DateTime1, DateTime2,DeltaDateTime, DeltaTime : TDateTime;
....
DeltaDateTime := abs(DateTime1-DateTime2);
DeltaTime := frac (DeltaDateTime);
The problem with that code is that in a situation where both original datetimes contain only the time (if they are set, for example, with
HourOf, an hypotheticall
EncodeTime, etc) the result is not what you might expect, as seen above.
An example: Imagine that you use two
TTimeEdit to get the times and that you want to know how much you slept this night: you went to bed at 22:30 (time1) and got up at 6:00 (time2): your code will tell you that you slept a whooping 16,5 hours instead of the 7,5h you really spent in bed. Note that inverting the terms (time1-time2) doesn't matter, since it just changes the sign of the substraction.
And what would be the best solution to round to second??
What I would do:
if Time1 > Time2 then
IncDay(Time2, 1);
Result := SecondsBetween(Time2, Time1);
{or, alternatively,
Result := Round(SecondSpan(Time2, Time1));
}