I\'m Using Kartik DateTimePicker Extension
= $form->field($model, \'Created\')->widget(DateTimePicker::classname(),[
\'model\' => $model,
I have simple code, in behavior:
public function behaviors() {
return [
[ 'class' => \yii\behaviors\TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
],
// if you're using datetime instead of UNIX timestamp:
'value' => new Expression('NOW()'),
]
];
}
for rules:
public function behaviors() {
return [
[ 'class' => \yii\behaviors\TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
],
// if you're using datetime instead of UNIX timestamp:
'value' => new Expression('NOW()'),
]
];
}