Solved

MinutesBetween() returns varying values.

Posted on 2002-05-12
5
1,420 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thankyou for your response.

Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now