Answer the question
In order to leave comments, you need to log in
Why is date not being saved from DatePicker Yii2?
in the shape of:
<?=
$order_form->field($order_model, 'date_delivery')->widget(DatePicker::classname(), [
'language' => 'ru', 'dateFormat' => 'dd-MM-yy',
'options'=>['class'=>' form-control input-sm'],
])
?>
public function rules() {
return [
...
[['date_delivery'], 'date','format'=>'dd-MM-yy','timestampAttribute'=>'date_delivery'],
[['date_delivery'], 'default', 'value' => null],
...
];
}
Answer the question
In order to leave comments, you need to log in
Check in what format the data goes to the database, you can see it in the debug.
Next, check in what format the data is stored in the database, as I understand it, 0000-00-00 is a clear sign that this is a year month day or year day month (but the first option is more likely)
Next, bring the data that the widget sends to the desired format and make sure that there is no additional logic in the model that changes the format.
Or vice versa, in the model, in beforeSave, change the format.
I can also draw your attention to this component:
demos.krajee.com/datecontrol
Which actually solves the issue of various formats in the database and on the front in widgets.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question