I have an XML document with an entry looking like this:
<recall-number id="F-2402-2015">
<product-type>Food</product-type>
<event-id>70195</event-id>
<status>Ongoing</status>
<recalling-firm>Northhampton Peanut Company</recalling-firm>
<city>Severn</city>
<state>NC</state>
<country>US</country>
<voluntary-mandated>Voluntary: Firm Initiated</voluntary-mandated>
<initial-firm-notification>Letter</initial-firm-notification>
<distribution-pattern>CT, MA, NJ, NY and PA.</distribution-pattern>
<classification>Class II</classification>
<product-quantity>unknown</product-quantity>
<reason-for-recall>Undeclared Non-Allergen: Sulfites</reason-for-recall>
<recall-initiation-date>12/24/2014</recall-initiation-date>
<report-date>06/10/2015</report-date>
</recall-number>
I'm using simplexml_load_file and am able to obtain all of the fields, however the two date fields at the end (recall-initiation-date/report-date) are showing up blank. After some research I used the date function:
function get_recalls() {
$url = "Enforcement-Reports-Export.xml";
$xml = simplexml_load_file($url);
foreach($xml->{'recall-number'} as $product) {
$recall_initiation_date = date('d/m/Y', $product{'recall-initiation-date'});
$report_date = date('d/m/Y', $product{'report-date'});
echo $recall_initiation_date;
echo $report_date;
}
}
However the date that it returns is 01/01/1970 and not the correct date.