0

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?

arun
  • 165
  • 1
  • 17

1 Answers1

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