2012-05-11 73 views
0

我有将日期保存到MySQL数据库中的问题。将日期保存到MySQL

我有这样的输入域:

<input type="date" name="theDate" id="theDate" required></p> 

之前,我将它保存到数据库中,我将字符串格式化为这样的日期:

date('Y.m.d', strtotime($table['day'])); 

数据库字段是DATE但它仅节省了0000-00-00

当我在保存之前回复日期时,正确的是2012-02-23

我希望任何人都可以告诉我这是如何完成的。

+3

很简单,在MySQL中期望的输入为'Y-M-D'。使用它来代替'Y.m.d'。 –

回答

2
date('Y.m.d', strtotime($table['day'])); 

输出2012.02.23没有2012-02-23 ......你需要

date('Y-m-d', strtotime($table['day'])); 

See this section on MySQL Date and Time literals

+0

感谢你们俩。 有时候,正确的答案就在你面前,但你需要有人指出...... (我现在很羞愧) – Frank