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
MinutesBetween(StrToTime('
MinutesBetween(StrToTime('
Brian
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Paul (pnh73)
EE Cleanup Volunteer
TDateTime is float type, so rounding isn't absolutely exact. I suppose MinutesBetween looks like:
Result:=Trunc(Abs(Time1-Ti
you may modify it
Result:=Trunc(0.000001+Abs