date not saving in mysql database

早过忘川 提交于 2019-12-06 08:28:08

I would guess this is the cause of your problem:

$evtStartDate->addValidator(new Zend_Validate_Date('dd-mm-YYYY'));

MySQL doesn't understand date literals in the format dd-mm-YYYY. MySQL understands YYYY-MM-DD or YY-MM-DD, and a few other variations.

See http://dev.mysql.com/doc/refman/5.1/en/datetime.html for official documentation on accepted date literal formats.


Re comment: You can either convert the date in your PHP code, or else you can insert an expressing using the STR_TO_DATE() MySQL function. Pass a Zend_Db_Expr object in place of the literal value.

$startdate_expr = $this->getAdapter()->quoteInto("STR_TO_DATE(?, '%d-%m-%Y')",
  $formdata["evt_startdate"]);
$formdata["evt_startdate"] = new Zend_Db_Expr($startdate_expr);

$enddate_expr = $this->getAdapter()->quoteInto("STR_TO_DATE(?, '%d-%m-%Y')",
  $formdata["evt_enddate"]);
$formdata["evt_enddate"] = new Zend_Db_Expr($enddate_expr);

$e->insert($formdata);

Or you can change your web application's form to require dates to be in YYYY-MM-DD format, and then you don't have to convert anything.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!