Reputation: 1559
I have an XML object being returned, and inside is a date and time code that looks like this,
[Date] => 20120229
[Time] => 032400
How can I convert those into a date and time like, 02-29-1012 and 03:24:00 ?
Thank you.
Upvotes: 0
Views: 873
Reputation: 784968
Use strtome like this:
$dt = date('m-d-Y h:i:s', strtotime($d . ' ' . $t));
TEST:
echo date('m-d-Y h:i:s', strtotime('20120229 032400')) . "\n";
OUTPUT:
02-29-2012 03:24:00
Upvotes: 1
Reputation: 33437
Assume Date is in $date and time in $Time.
$d = DateTime::createFromFormat('YmdHis', $date.$time);
echo $d->format('m-d-Y H:i:s');
http://www.php.net/manual/en/datetime.createfromformat.php
Upvotes: 3