I am using yii2 datepicker in my project. I want to show selected date as dd/mm/YYYY but want to save date in model as YYYY-mm-dd. How can I do so?
Asked
Active
Viewed 1,182 times
1 Answers
1
You can format datepicker in Controller,and then render the view.
Controller:
$model->birth_date=Yii::$app->formatter->asDate($model->birth_date, "dd/mm/yyyy");
Then Store like this:
$model->birth_date=Yii::$app->formatter->asDate($model->birth_date, "yyyy-mm-dd");

Hack it
- 405
- 2
- 10