Hi,
I’m facing this issue. I want to use a d/m/Y formatted date and insert it in a MySQL database date column. So I use CDbExpression like this:
$model->birthdate = new CDbExpression("STR_TO_DATE(:date, '%d/%m/%Y')", [':date' => $model->fmtBirthDate]);
As I wrote, $model->fmtBirthDate has the format dd/mm/yyyy (like ‘15/05/2017’). However, the previous line fails with database error:
CDbCommand failed to execute the SQL statement: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: 'STR_TO_DATE(:date, '%d/%m/%Y')' for column 'birthdate' at row 1. The SQL statement executed was: UPDATE `t_member` SET `id`=:yp0, `birthdate`=:yp1 WHERE `t_member`.`id`=69121. Bound with :yp0=69121, :yp1='STR_TO_DATE(:date, \'%d/%m/%Y\')'
What is wrong here?Tried it with 1.1.17 and 1.1.18 and still the same error.
Of course
select str_to_date('15/05/2017', '%d/%m/%Y');
works just fine in a mysql prompt.
Any help would be greatly appreciated.