Created date getting set to 0000-00-00 00:00:00 with the CTimestampBehavior in yii while updating

StackOverflow https://stackoverflow.com/questions/18140746

  •  24-06-2022
  •  | 
  •  

I have attached time stamp behavior to my Model as:

public function behaviors()
{
    return array(
        'CTimestampBehavior' => array(
        'class' => 'zii.behaviors.CTimestampBehavior',
        'createAttribute' => 'created_date',
        'updateAttribute' => 'modified_date',
        'setUpdateOnCreate' => true,
        ),
    );
}

It is setting the created and modified date correct while creating the record. While updating it updates the modified date correctly but sets the created date to 0000-00-00 00:00:00. Is there any thing wrong in this code?

I'm using the $Model->update() function for updating the record.

有帮助吗?

解决方案

Found the solution. Found that the date format for created data was incorrect and therefore was not getting stored in the database. Changed the created date into the correct format before updating the model and its working.

$model->created_date=date("Y-m-d H:i", strtotime($model->created_date));    
$model->update();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top