Link to home
Start Free TrialLog in
Avatar of Traal
Traal

asked on

MinutesBetween() returns varying values.

Why do the following two calls to MinutesBetween return two different values?  I've tried substituting equivalent TDateTime values in place of the StrToTime calls, with the same result.

MinutesBetween(StrToTime('12:00'), StrToTime('13:00')) = 59.

MinutesBetween(StrToTime('13:00'), StrToTime('14:00')) = 60.

Brian
Avatar of MBo
MBo

What is MinutesBetween function?
TDateTime is float type, so rounding isn't absolutely exact. I suppose MinutesBetween looks like:

Result:=Trunc(Abs(Time1-Time2)/1440);

you may modify it

Result:=Trunc(0.000001+Abs(Time1-Time2)/1440);
Avatar of Traal

ASKER

It's in DateUtils, and looks like this:

function MinutesBetween(const ANow, AThen: TDateTime): Int64;
begin
  Result := Trunc(MinuteSpan(ANow, AThen));
end;


function MinuteSpan(const ANow, AThen: TDateTime): Double;
begin
  Result := MinsPerDay * SpanOfNowAndThen(ANow, AThen);
end;


function SpanOfNowAndThen(const ANow, AThen: TDateTime): TDateTime;
begin
  if ANow < AThen then
    Result := AThen - ANow
  else
    Result := ANow - AThen;
end;

Brian
ASKER CERTIFIED SOLUTION
Avatar of MBo
MBo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from MBo

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
Thankyou for your response.

Paul (pnh73)
EE Cleanup Volunteer