Reputation: 7
I have a date string that looks like this:
Mon Jun 20 2016 00:00:00 GMT-0400 (Eastern Daylight Time)
and I want to insert into a mysql datetime
column like this %Y-%m-%d %H:%i
. I tried using php DateTime
, but it gives me an error because there are two time zones. I can't change the returned string because it's the return value for a function in an api I'm using. How can I get this to the right format?
Upvotes: 0
Views: 36
Reputation: 2023
If you try this:
$string = 'Mon Jun 20 2016 00:00:00 GMT-0400 (Eastern Daylight Time)';
$string = preg_replace('/\(.*\)/', '', $string);// remove (Eastern Daylight Time)
echo date('Y-m-d H:i', strtotime($string));
Would print out:
'2016-06-20 00:00'
Hope this helps.
Upvotes: 1