Could anyone help convert "5/9/2018 10:15:19" to "2018-05-09 10:15:19" using php "explode"method?
First question ever here ... be gentle on me!
Could anyone help convert "5/9/2018 10:15:19" to "2018-05-09 10:15:19" using php "explode"method?
First question ever here ... be gentle on me!
As others have said, there is a better way to achieve this but if you must use explode then this code will do the job.
<?php
$input = '5/9/2018 10:15:19';
$date_and_time = explode(' ', $input);
$date = $date_and_time[0];
$time = $date_and_time[1];
$split_date = explode('/', $date);
$year = $split_date[2];
$month = $split_date[1];
$day = $split_date[0];
$output = $year . '-' . $month . '-' . $day . ' ' . $time;
echo $output;