I’m trying to manipulate date/time in php. The dates are in this format: 30/04/2021 23:59:00 and I want to change them to: e.g. 2021-05-08 13:47:20 so effectively YYYY-MM-DD HH:MM:SS.
This is the code I’ve got but it doesn’t output anything except NaN:NaN:NaN - is there anything that anyone can see is obviously wrong with this. I’ve not done much PHP before so
function my_date($date_orig) {
try {
$date_time = explode(" ", $date_orig);
$dmy = explode("/", $date_time[0]);
return strtotime($dmy[2]."-".$dmy[1]."-".$dmy[0]." ".$date_time[1]);
} catch (Exception $e) {
return null;
}
}