将Y / M / d H:i转换为php格式的db格式[复制]

This question already has an answer here:

I have code:

$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 anywhere.

</div>

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

Normally you would use the following code:

date('Y-m-d H:i:s', strtotime($date.' '.$time));

If it returns the year 1970, then the input date (the one from $date variable) is not formatted according to a standard that can be recognised by php.