CBuzatu
CBuzatu

Reputation: 775

insert into MySQL server real time and date

I have this MySQL query:

$SQLquery = "INSERT INTO `experimental`.`comments` (`comment_id`, `comment_dt`) 
             VALUES (NULL, CURRENT_TIMESTAMP);";

When I execute this line with PHP into the MySQL Database at comment_dt row appears my computer local time and date. Does anybody know how to set to appear in my database a server local and time date?

Upvotes: 1

Views: 2740

Answers (2)

user319198
user319198

Reputation:

The best way will be that you should make your comment_dt column DATETIME type and set default value CURRENT_TIMESTAMP. No need to manually insert it through insert query.

Using this each time your comment_dt will be automatically updated with server date-time whenever a new row inserted.

ALTER TABLE comments ADD comment_dt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP 

Upvotes: 1

dhchen
dhchen

Reputation: 1198

$SQLquery = "INSERT INTO `experimental`.`comments` (`comment_id`, `comment_dt`) VALUES (NULL, CURRENT_TIMESTAMP());";

use MySQL Server function CURRENT_TIMESTAMP()

Upvotes: 1

Related Questions