Mysql timestamp in milliseconds

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Mysql timestamp in milliseconds

Post by kaffeburk » Wed 24 May 2017 00:22

How to get the current time from the MYSQL server in milliseconds? I only get it in whole seconds.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Mysql timestamp in milliseconds

Post by ViktorV » Wed 24 May 2017 10:57

To get a value with milliseconds you can use the following code:

Code: Select all

var
  ms: Integer;
begin
  UniQuery.SQL.Text := 'SELECT NOW(3)';
  UniQuery.Open;
  ms := UniQuery.Fields[0].AsSQLTimeStamp.Fractions;

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Re: Mysql timestamp in milliseconds

Post by kaffeburk » Wed 24 May 2017 11:26

Thanx but i cant get it to work:

Code: Select all

procedure TForm7.Button7Click(Sender: TObject);
var
  ms  : Integer;
  q   :TUniQuery;

begin

     q:=TUniQuery.Create(nil);
     q.Connection:=MainCon;
     q.SQL.Text := 'SELECT NOW(3)';
     q.Open;
     ms := q.Fields[0].AsSQLTimeStamp.Fractions;
     Memo1.Lines.Add(IntToStr(ms));
     q.Free;
end;

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Mysql timestamp in milliseconds

Post by ViktorV » Wed 24 May 2017 12:51

Please provide the exact versions of the used MySQL Server and IDE. Also specify whether the ms variable value equals 0.

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Re: Mysql timestamp in milliseconds

Post by kaffeburk » Wed 24 May 2017 13:11

ViktorV wrote:Please provide the exact versions of the used MySQL Server and IDE. Also specify whether the ms variable value equals 0.
Yes it returns 0

Mysql 5.5.45
Delphi 10.2
Unidac 7.0.1

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Mysql timestamp in milliseconds

Post by ViktorV » Wed 24 May 2017 13:39

This behavior occurs due to MySQL 5.5.45 architecture specificity, but not UniDAC functionality. Before MySQL version 5.6.4, MySQL does not support milliseconds (more precise: fractional seconds) in TIME, TIMESTAMP and DATETIME: https://dev.mysql.com/doc/refman/5.6/en ... conds.html

Post Reply