Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# MinutesBetween() returns varying values.

Posted on 2002-05-12
Medium Priority
1,469 Views
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
0
Question by:Traal
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 1

Expert Comment

ID: 7005219
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);
0

Author Comment

ID: 7005231
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
0

LVL 1

Accepted Solution

MBo earned 150 total points
ID: 7005613
Oh, my mistake- I've written /1440 instead of *1440
Make this function
function MinutesBetweenEx(const ANow, AThen: TDateTime): Int64;  // Integer is enough
begin
Result:=Trunc(0.000001+Abs(Time1-Time2)*1440);
end;
0

LVL 1

Expert Comment

ID: 9005739
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:

Paul (pnh73)
EE Cleanup Volunteer
0

LVL 1

Expert Comment

ID: 9017626

Paul (pnh73)
EE Cleanup Volunteer
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
###### Suggested Courses
Course of the Month5 days, 12 hours left to enroll