I have to import some data from a csv file where the dates have been stored in the following format:
15/07/2019 11:16:13
I need to convert this to
2019-07-15 11:16:13
I tried
$time = strtotime($column [2]);
$column_2 = date('Y-m-d H:i:s',$time);
where $column [2] is the csv column where this data is held, but it just returned a date of 1970-01-01 01:00:00
When I echo $time it is empty, so I'm guessing strtotime doesn't work on the date time format I'm trying to use.
What is the correct method for doing this?
You can use DateTime::createFromFormat()
$time = DateTime::createFromFormat('d/m/Y H:i:s', $column[2]);
$column_2 = $time->format('Y-m-d H:i:s');