$date = mysql_real_escape_string($_POST['intake_date']);
1. If your MySQL column is DATE
type:
$date = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
2. If your MySQL column is DATETIME
type:
$date = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date)));
You haven't got to work strototime()
, because it will not work with dash -
separators, it will try to do a subtraction.
Update, the way your date is formatted you can't use strtotime()
, use this code instead:
$date = '02/07/2009 00:07:00';
$date = preg_replace('#(d{2})/(d{2})/(d{4})s(.*)#', '$3-$2-$1 $4', $date);
echo $date;
Output:
2009-07-02 00:07:00
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…