Answer the question
In order to leave comments, you need to log in
How to convert date from DatePicker in yii2?
Good afternoon. When creating a post, the date picker format must be 'dmyyyy', actually
$form->field($model, 'date')->widget(DatePicker::className(), [
'value' => date('d.m.yyyy', strtotime('+2 days')),
'options' => ['placeholder' => 'Select issue date ...'],
'pluginOptions' => [
'format' => 'd.m.yyyy',
'todayHighlight' => true
]
])
[['date'], 'date', 'format' => 'php:d.m.yy'],
Answer the question
In order to leave comments, you need to log in
Or in beforeSave, convert the date to the required database format. I use the written behavior and connect it in the right place to the right attributes. I can send an example if needed.
I propose to store the date in Unix format. And convert to human form. It will be more versatile.
Also the date format of this plugin should be dd.mm.yyyy
If you want to put validation for this format use format=> php: dmY
This format definitely works: 'dd.mm.yyyy'
[['date'], 'date', 'format' => 'dd.mm.yyyy']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question