Reputation: 557
Hey I need to insert current datatime into mysql database.. this is the format:
0000-00-00 00:00:00
Upvotes: 0
Views: 9406
Reputation: 270775
Most easily done with MySQL directly using the NOW()
function.
INSERT INTO tbl (datecol) VALUES (NOW());
If you need PHP to produce a value other than the exact current timestamp, use the format:
date('Y-m-d H:i:s', $some_unix_timestamp);
Upvotes: 6
Reputation: 28793
As a MySQL query:
INSERT INTO table (fieldname) VALUES (NOW())
And wrapped in PHP:
$db = new PDO($dsn, $user, $password);
$db->query("INSERT INTO table (fieldname) VALUES (NOW())");
Upvotes: 2