Mysql table has a column DatePosted with the Datatype as TIMESTAMP
.
I am trying to insert the current TIMESTAMP into the table using PHP. However the below code does not seem to work i get 0000-00-00 00:00:00
. Is the format wrong how do i get the current timestamp to be inserted in mysql
TIMESTAMP.php file
date_default_timezone_set('America/Los_Angeles');
echo date("j of F Y, \a\\t g.i a", time());
mysqli_query($con,"INSERT INTO cfv_timestamp (DatePosted) VALUES ('".date("j F Y, \a\\t g.i a", time())."' )");
.
CREATE TABLE `cfv_timestamp (
`DatePosted` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
You should check mysql Timestamp format and change yours.
mysqli_query($con,"INSERT INTO cfv_timestamp (DatePosted)
VALUES ('".date("Y-m-d H:i:s", time())."' )");
Also you could set default value for Timestamp type CURRENT_TIMESTAMP
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.