I'm trying to parse a date time string combination to Date and Time and wanted to know if there a smarter way
Sample Data
9/3/2013 8:50:05 AM
9/4/2013 1:42:28 PM
9/11/2013 12:01:21 PM
....
Here's what I'm doing..Looking thru the list of Date Time string
<?php
$x = "9/3/2013 8:50:05 AM"
$ExDt = str_getcsv(trim($x," ");
$ExDate = $ExDt[0];
$ExTm = $ExDt[1] . " " . $ExDt[2];
$ExTime = date("H:i:s", strtotime($ExTm)); // Change to 24 hour format
echo $ExDate;
echo $ExTime;
?>
I feel safer converting with this (timezone not taken into account in the example)
$start = '25/12/2013 10:13:46';
$new_date = DateTime::createFromFormat('d/m/Y H:i:s', $start);
echo $new_date->format('Y-m-d H:i:s');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With