user4131013 user4131013 - 1 month ago 7
MySQL Question

php how join string date and time separates and convert format Y-m-d H:i:s

I have two string separates date and time, I need you to join these and convert in format Y-m-d H:i:s

time
214323

date
131016

<?php

$data0 ="214323,131016" ;

$data1 = explode( ',', $data0);

$time = $data1[0];
$date = $data1[1];


I need you 2016-10-13 21:43:23

Answer

Use the DateTime class to parse the special format and format it into the desired format.

$dt = DateTime::createFromFormat('His,dmy', '214323,131016');
echo $dt->format('Y-m-d H:i:s');

https://3v4l.org/UV48B

Comments