Page 1 of 1

Mysql timestamp in milliseconds

Posted: Wed 24 May 2017 00:22
by kaffeburk
How to get the current time from the MYSQL server in milliseconds? I only get it in whole seconds.

Re: Mysql timestamp in milliseconds

Posted: Wed 24 May 2017 10:57
by ViktorV
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;

Re: Mysql timestamp in milliseconds

Posted: Wed 24 May 2017 11:26
by kaffeburk
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;

Re: Mysql timestamp in milliseconds

Posted: Wed 24 May 2017 12:51
by ViktorV
Please provide the exact versions of the used MySQL Server and IDE. Also specify whether the ms variable value equals 0.

Re: Mysql timestamp in milliseconds

Posted: Wed 24 May 2017 13:11
by kaffeburk
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

Re: Mysql timestamp in milliseconds

Posted: Wed 24 May 2017 13:39
by ViktorV
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