Bug in TimeDiff interpretation using MyDAC

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
John Smith22
Posts: 15
Joined: Thu 19 Apr 2012 13:49

Bug in TimeDiff interpretation using MyDAC

Post by John Smith22 » Mon 07 Apr 2014 08:40

I have a problem that the TimeDiff function in MySQL returns erroneous results in MyDAC.

Consider the following example when run from the command console of MySQL:

Code: Select all

mysql> select timediff("2014-04-05 13:00:00", "2014-04-02 13:00:00");
+--------------------------------------------------------+
| timediff("2014-04-05 13:00:00", "2014-04-02 13:00:00") |
+--------------------------------------------------------+
| 72:00:00                                               |
+--------------------------------------------------------+
1 row in set (0.00 sec)
This result (72:00:00) is correct as the difference is 3 days (3*24h=72h).

When executed in MyDAC as this:

Code: Select all

procedure TForm5.Button1Click(Sender: TObject);
var Result : String ;
begin
  MyConnection1.Server := 'localhost' ;
  MyConnection1.Port := 3306 ;
  MyConnection1.Username := 'user' ;
  MyConnection1.Password := 'pw123' ;
  MyConnection1.Connect ;
  MyQuery1.Connection := MyConnection1 ;
  MyQuery1.SQL.Text := 'select timediff("2014-04-05 13:00:00", "2014-04-02 13:00:00");' ;
  MyQuery1.Execute ;
  Result := MyQuery1.Fields[0].AsString ;
end;
Result is returned as 00:00:00, which is incorrect.
Is this a bug or am I doing something wrong?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Bug in TimeDiff interpretation using MyDAC

Post by AlexP » Mon 07 Apr 2014 11:56

Hello,

The TTime form in Delphi doesn't support values greater than 24 hours, therefore 0:00:00 is displayed. If you need to get the difference in hours, you can use the TIMESTAMPDIFF MySQL functions, for example:

Code: Select all

select TIMESTAMPDIFF(HOUR, "2014-04-05 13:00:00", "2014-04-02 13:00:00")

John Smith22
Posts: 15
Joined: Thu 19 Apr 2012 13:49

Re: Bug in TimeDiff interpretation using MyDAC

Post by John Smith22 » Tue 08 Apr 2014 06:59

OK. I understand now.
Are there similar constraints I should be aware of when calling TIMESTAMPDIFF in Delphi using HOUR or MINUTE?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Bug in TimeDiff interpretation using MyDAC

Post by AlexP » Tue 08 Apr 2014 09:18

Just like to hours, the same restrictions are imposed to minutes and seconds in Delphi - the value of minutes and seconds can't be greater than 59

Post Reply