Question

I have two separate strings for date and time formatted something like: 14/04/2014 and 01:15 PM

I would like to convert these to a datetime formatted as Y-m-d H:i:s

Any idea how I go about this??

Was it helpful?

Solution

$date = DateTime::createFromFormat('d/m/Y h:i A', '14/04/2014'.' '.'01:15 PM');
echo $date->format('Y-m-d H:i:s');

Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top