Skip to content
Advertisement

Yii2 kartik/date/datepicker shows wrong format while update

I use kartik DatePicker in my activeform.

JavaScript

My activeform field:

JavaScript

While creating I save it as a UTC date format :

JavaScript

When I update, it shows as

enter image description here

I need this as

enter image description here

Advertisement

Answer

You have to provide the formatted date to the widget.

  • When using ActiveForm you can override afterFind() for the specific model to format the date and override the default timestamp value for the transferred_date field.

  • For Formatting, you can use the yii-i18n-formatter component by defining inside the config file common/config/main.php if using advanced-app, or config/web.php if using basic-app.

    Add below in the config file

    JavaScript

    Add below into your model

    JavaScript

Now change the field definition to below and refresh the page

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement