Solved

MinutesBetween() returns varying values.

Posted on 2002-05-12
5
1,434 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 50 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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