mysql - Convert date mm-dd-yyyy to yyyy-mm-dd in php -
i want convert date field(format: dd-mm-yyyy) db date format. if input date format equal dd-mm-yyyy
format convert date yyyy-mm-dd
format else return false.
function converttodbdate($date) { if($date !="") { $result= date('y-m-d', strtotime(str_replace('/', '-', $date))); if($result) { return $result; } return false; } }
you can use datetime::createfromformat
$result_date = datetime::createfromformat('d/m/y', "23/02/2016");
echo $date->format('y-m-d');
Comments
Post a Comment