Prashant Sharma Prashant Sharma - 2 years ago 88
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 :-)


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download