Cdbexpression For Date_Add Not Working

Hi guys,

I’m using XAMPP with Yii 1.1.15

When I try to use $this->attr = CDbExpression(‘DATE_ADD(NOW(), INTERVAL 30 DAY)’); in my beforeSave function, the field in the database is updated with just NOW() instead of adding the days to date. In MySQL WorkBench the instruction works fine.

The instruction $this->attr = CDbExpression(‘NOW()’); works fine also.

The field is defined as DATETIME in MySQL

Do you have any advice on how could I update the field with the DATE_ADD expression?

Thanks in advance

Regards

I use a similar setup to set a column with a default date value:




$this->value = new CDbExpression("TO_DATE('".gmdate('Y-m-d H:i:s')."','YYYY-MM-DD HH24:MI:SS')");



The only difference I see is the ‘new’ identifier when using CDbExpression.

You could consider adding 30 days in php and use the outcome as the value of your attribute:




date('Y-m-d H:i:s', strtotime("+30 days"))