Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MinutesBetween() returns varying values.

Posted on 2002-05-12
5
Medium Priority
?
1,487 Views
Last Modified: 2012-06-21
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
Comment
Question by:Traal
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:MBo
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

by:Traal
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

by:
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

by:pnh73
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:

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
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9017626
Thankyou for your response.

Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question