Reputation: 4050
I've set of dates that look like this Sat, 16 Apr 2016 16:29:06 +0000
Who can I convert them to MySql timestamp format using PHP?
Upvotes: 0
Views: 59
Reputation: 8371
You can use format method of Datetime
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
output
2000-01-01 00:00:00
Or else you can try date function of PHP
<?php
$date = "now";//Date in any common format
echo date("Y-m-d H:i:s",strtotime($date))
?>
Note* In above example I am using strtotime function to convert string date to PHP timestamp
output
2016-04-20 07:14:46
Upvotes: 0
Reputation: 7143
$timestamp = $date_time->getTimestamp();
documentation: http://php.net/manual/en/datetime.gettimestamp.php
Upvotes: 2