Prashant Sharma Prashant Sharma - 7 months ago 11
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 :-)

thanks

Answer

This way will solve your problem.

<?php
$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;
?>

Result

More Examples;

http://www.w3schools.com/php/func_date_strtotime.asp

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

Comments