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