Mysql added datetime

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
croc
Posts: 6
Joined: Sun 02 Nov 2014 17:30

Mysql added datetime

Post by croc » Sun 09 Nov 2014 01:47

When I sent this to a datetime field: date ''2014-11-09 12:08:43'' this will work. But what should I sent to take the server time of my mysql server?

croc
Posts: 6
Joined: Sun 02 Nov 2014 17:30

Re: Mysql added datetime

Post by croc » Sun 09 Nov 2014 13:31

I would like to have the mysql server time if that is not possible sent the client time.

When I take the client time like this:

' + QuotedStr(Datetostr(Date) +' '+ timetostr(now))+ ' for instead of ''2014-11-09 12:08:43''
It doesn't work.

How can I fix this ??

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

Re: Mysql added datetime

Post by ViktorV » Mon 10 Nov 2014 09:16

To set client time in a SQL query, you can use the following code:

Code: Select all

QuotedStr(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now))
To get the current time of a MySQL server, you can use the following SQL query:

Code: Select all

Select Now()

croc
Posts: 6
Joined: Sun 02 Nov 2014 17:30

Re: Mysql added datetime

Post by croc » Mon 10 Nov 2014 22:46

hmm maybe I am doing something wrong.

It doesn't work.

UniConnection1.ExecSQL('INSERT INTO `test` (`TEMP`, `DATE & TIME`) VALUES (''14.2C'', QuotedStr(Select Now()) );');

How to get the Select Now() to work ?

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

Re: Mysql added datetime

Post by ViktorV » Tue 11 Nov 2014 08:16

To solve the problem, please try using the following code:

Code: Select all

UniConnection1.ExecSQL('INSERT INTO test (`TEMP`, `DATE & TIME`) VALUES (''14.2C'', Now())');

croc
Posts: 6
Joined: Sun 02 Nov 2014 17:30

Re: Mysql added datetime

Post by croc » Wed 12 Nov 2014 21:30

Thanks :) this works.

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

Re: Mysql added datetime

Post by ViktorV » Thu 13 Nov 2014 11:19

It is good to see that the problem has been solved.
Feel free to contact us if you have any further questions.

Post Reply