Trying to convert dates being scraped with xpath to mysql datetime format and having some trouble. The below is my date, and my function to convert the date, and my desired output:
$date = ' 8-May-2014';
$date_fixed = date("Y-m-d H:i:s", strtotime(trim($date)));
echo $date; // ' 8-May-2014'
echo $date_fixed; // '2014-05-08 00:00:00'
The issue is that when I run this in my server (php7), and the date is set from an xpath nodeValue, the conversion comes back at the epoch time instead, even though the value of that node is the date string. I var_dump'ed the nodeValues to verify they are strings, and they are. I tried setting the nodeValue to a new variable and then converting that, still doesn't work.
$date = $xpath->query('./td[2]', $row)->item(0)->nodeValue; // ' 8-May-2014'
$date_fixed = date("Y-m-d H:i:s", strtotime($date));
echo $date_fixed; // '1970-01-01 00:00:00'
I'm not sure what I'm missing.