Prashant Sharma Prashant Sharma - 9 months ago 18
PHP Question

convert Y/M/d H:i to db format in php

I have

$date= "2016/Apr/16";
$time="5:00 PM";

I want to convert it to DB format like
2016-04-16 17:00:00
in php .
I am not getting exact code from any where, please help :-)



This way will solve your problem.

$date= "2016/Apr/16";
$time="5:00 PM";
$fullDate = str_replace('/','-',$date) . " " . $time;
$newDate = date("Y-m-d H:i:s", strtotime($fullDate));
echo $newDate;


More Examples;

Convert date format yyyy-mm-dd => dd-mm-yyyy