Brad Bansner
asked on
Convert date format in PHP to Y-m-d H:i:s
I have been given an XML data feed containing dates which look like this:
<pubDate>Mon, 10 Aug 2015 19:23:30 +0000</pubDate>
I need to convert that into Y-m-d H:i:s for insert via WordPress' wp_insert_post which requires that format. Its very strict, I tried using "8" for August and it errored out, required me to use "08".
My question is, what is the best way to go about this? I could obviously pick it apart piece by piece with a bunch of PHP script but that seems wasteful. Is there a better way?
Thanks!
<pubDate>Mon, 10 Aug 2015 19:23:30 +0000</pubDate>
I need to convert that into Y-m-d H:i:s for insert via WordPress' wp_insert_post which requires that format. Its very strict, I tried using "8" for August and it errored out, required me to use "08".
My question is, what is the best way to go about this? I could obviously pick it apart piece by piece with a bunch of PHP script but that seems wasteful. Is there a better way?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For future reference when working with date/time values in PHP and MySQL:
https://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html
https://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html
ASKER