Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

FPC GO32 2.6.2 wrong result from SecondsBetween

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lubomír Čabla

I am doing something wrong?

When I encode the date and time then for SecondsBetween I get 59 instead of 60 and for MilliSecondsBetween also. When I encode only time then for SecondsBetween I get correct answer 60.

Free Pascal Compiler version 2.6.2 [2013/02/12] for i386 Target: GO32 v2, i386

Results from dt.pp:

ShortDateFormat=d/m/y
LongDateFormat=dd" "mmmm" "yyyy
ShortTimeFormat=hh:nn
LongTimeFormat=hh:nn:ss

Encode date and time:
DateTime DT1= 28.05.2013 15:26:01:0
DateTime DT2= 28.05.2013 15:27:01:0
Between DT2-DT1= 0.0:0:59:59999

Encode time only:
DateTime DT1= 30.12.1899 15:26:01:0
DateTime DT2= 30.12.1899 15:27:01:0
Between DT2-DT1= 0.0:1:60:60000

Btw. FormatDateTime('dd.mm.yyyy hh:nn:ss:z',DT1));

the result is the same with the use 'mm' instead of 'nn' for minutes:

FormatDateTime('dd.mm.yyyy hh:mm:ss:z',DT1));

Lubomir Cabla

Reply by email

Bart
to Lubomír Čabla
Lubomír Čabla wrote
I am doing something wrong?

Probably rounding errors:

  DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0);

2 calculations on floating numbers

  DT1:=EncodeTime(15,26,1,0);
1 calculation on floating numbers

Bart

Reply by email

Lubomír Čabla
to Bart

It may be, but I tried to use EncodeDateTime with the same result:

DT1:=EncodeDateTime(2013,5,28,15,26,1,0);
DT2:=EncodeDateTime(2013,5,28,15,27,1,0);

Function EncodeDateTime calls TryEncodeDateTime that uses TryEncodeDate and TryEncodeTime.

This is only a test, I want to be sure that after comparing the two values ​​get the correct time difference and 59 seconds is not correct.

Bart wrote 15 lines
On 9/17/13, Lubomír Čabla wrote: > I am doing something wrong? Probably rounding errors: DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0); 2 calculations on floating numbers DT1:=EncodeTime(15,26,1,0); 1 calculation on floating numbers Bart _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to Lubomír Čabla
Lubomír Čabla wrote 11 lines
It may be, but I tried to use EncodeDateTime with the same result: DT1:=EncodeDateTime(2013,5,28,15,26,1,0); DT2:=EncodeDateTime(2013,5,28,15,27,1,0); Function EncodeDateTime calls TryEncodeDateTime that uses TryEncodeDate and TryEncodeTime. This is only a test, I want to be sure that after comparing the two values ​​get the correct time difference and 59 seconds is not correct.

As a principle, you can never avoid such errors if using floating point numbers. If you need absolutely precise results, use integers.

Tomas

Show quoted text 21 lines
On Tue, Sep 17, 2013 at 6:15 PM, Bart wrote: > On 9/17/13, Lubomír Čabla wrote: > > I am doing something wrong? > > Probably rounding errors: > DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0); > 2 calculations on floating numbers > > DT1:=EncodeTime(15,26,1,0); > 1 calculation on floating numbers > > Bart > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Lubomír Čabla
to Tomas Hajny

Yes, I know, you are right, so far I've used DOS utility GetDate/GetTime without any errors.

I wanted to update the old compiler 1.x to the new version, but it seems will stay with the old version.

Thank you for your help.

Tomas Hajny wrote 47 lines
On Tue, September 17, 2013 20:22, Lubomír Čabla wrote: > It may be, but I tried to use EncodeDateTime with the same result: > > DT1:=EncodeDateTime(2013,5,28,15,26,1,0); > DT2:=EncodeDateTime(2013,5,28,15,27,1,0); > > Function EncodeDateTime calls TryEncodeDateTime that uses TryEncodeDate > and > TryEncodeTime. > > This is only a test, I want to be sure that after comparing the two values > get the correct time difference and 59 seconds is not correct. As a principle, you can never avoid such errors if using floating point numbers. If you need absolutely precise results, use integers. Tomas > > On Tue, Sep 17, 2013 at 6:15 PM, Bart wrote: > >> On 9/17/13, Lubomír Čabla wrote: >> > I am doing something wrong? >> >> Probably rounding errors: >> DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0); >> 2 calculations on floating numbers >> >> DT1:=EncodeTime(15,26,1,0); >> 1 calculation on floating numbers >> >> Bart >> _______________________________________________ >> fpc-pascal maillist - >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to Lubomír Čabla
Lubomír Čabla wrote 5 lines
Yes, I know, you are right, so far I've used DOS utility GetDate/GetTime without any errors. I wanted to update the old compiler 1.x to the new version, but it seems will stay with the old version.

There should be no problem to continue using GetDate/GetTime with current FPC version.

Tomas

Show quoted text 22 lines
On Tue, Sep 17, 2013 at 8:31 PM, Tomas Hajny wrote: > On Tue, September 17, 2013 20:22, Lubomír Čabla wrote: > > It may be, but I tried to use EncodeDateTime with the same result: > > > > DT1:=EncodeDateTime(2013,5,28,15,26,1,0); > > DT2:=EncodeDateTime(2013,5,28,15,27,1,0); > > > > Function EncodeDateTime calls TryEncodeDateTime that uses > TryEncodeDate > > and > > TryEncodeTime. > > > > This is only a test, I want to be sure that after comparing the two > values > > get the correct time difference and 59 seconds is not correct. > > As a principle, you can never avoid such errors if using floating point > numbers. If you need absolutely precise results, use integers. > > Tomas

Reply by email