I'm Using Kartik DateTimePicker Extension
<?= $form->field($model, 'Created')->widget(DateTimePicker::classname(),[
'model' => $model,
'attribute' => 'Created',
'name' => 'Created',
'options' => ['placeholder' => 'Select Created'],
'pluginOptions' => [
'format' => 'dd-mm-yyyy hh:ii:ss',
'todayHighlight' => true
]
])
?>
User fill the Create Date the format is
d-m-Y H:i:s (like 24-09-2015 11:21:10)
But when record save to database then Create Date Format change to
Y-m-d H:i:s (like 2015-09-24 11:21:10)
How can I change the date format on save/update of record
Finally I found the answer using AttributeBehavior.
In my model class I've write the behaviors code:
My Model Class
If input format is d/m/Y then you need to replace the "/" by "-"
like: input date(created): 10/09/2015
I have simple code, in behavior:
for rules:
Need to just add this code before save/update model in controller.
like,
OR
For more information refer this link
use in active form
'clientOptions' => ['alias' => 'dd-mm-yyyy'],
use in active form
use class
Class yii\widgets\MaskedInput
Example