newneub newneub - 5 months ago 15
MySQL Question

Convert to DATETIME from "Fri, 10 Jun 2016 14:30:38 -0500"

I am trying to pull RSS data from a page and upload it to my database.

example:

<dc:date>Fri, 10 Jun 2016 14:30:38 -0500</dc:date>


the -0500 is the trouble.

what I usually do:

$dc1 = $xml->channel->item[$i]->children($namespaces["dc"]);
$pubDate1 = $dc1->date;
$pubDate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $pubDate1)));


Should I be defining $pubDate differently?

Answer

No need of replacing '-' with '/'. You can directly pass the $pubDate1

$dc1 = $xml->channel->item[$i]->children($namespaces["dc"]);
$pubDate1 = $dc1->date; // 'Fri, 10 Jun 2016 14:30:38 -0500'
$pubDate = date('Y-m-d H:i:s', strtotime($pubDate1));

OutPut :

2016-06-11 12:30:38

Comments