Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MinutesBetween error 1

Status
Not open for further replies.

bbegley

Programmer
Joined
Apr 29, 2002
Messages
228
Location
US
Does anyone know if the MinutesBetween error has been fixed in Delphi 7?
By putting a button and two edit boxes on a screen, we get this problem (it also occurs in our real application, which is how we found it):

If you enter 08:00 in edit1 and 07:40 in edit2, Minutes between returns 20, which is correct. If you enter any number between 07:42 and 07:59, the value is off by 1. This is the case in a large number of cases.

procedure TfrmMain.Button1Click(Sender: TObject);
var
DateTime1:TDateTime;
DateTime2:TDateTime;
begin
DateTime1 := StrToTime(Edit1.text);
DateTime2 := StrToTime(edit2.text);

Showmessage(IntToSTr(DateUtils.MinutesBetween(DateTime1,DateTime2)));
end;


Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
I'm still on D5, so the only way I can do it is:
[blue]
Code:
ShowMessage( FloatToSTr( Round((DateTime1 - DateTime2) * 24 * 60)));
[/color]

 
You are right that does work. I wonder why Borland chose to implement their MinutesBetween function like this:

function MinutesBetween(const ANow, AThen: TDateTime): Int64;
begin
Result := Trunc(MinuteSpan(ANow, AThen));
end;

It appears that Round operates more accurately than trunc here.

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top