Search code examples
phpdatetimedate-conversion

PHP convert separate date and time strings into single datetime


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??


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