S
S
Sergey Beloventsev2018-07-11 14:21:06
Yii
Sergey Beloventsev, 2018-07-11 14:21:06

What is wrong with datatime?

To form the date I use kartik-v yii2-widget-datepicker here is the repository
for tz there was a condition if the date is not filled then display '00-00-0000' in editing.
for this I did this in the form

form->field($model, 'date')->textInput()->widget(DatePicker::class, [
        'options' => [
          'placeholder' => 'Enter birth date ...',
          'value'=>($model->date)?date('d-m-Y',strtotime($model->date)):null,
        ],
        'pluginOptions' => [
          'autoclose'=>true,
          'format' => 'dd-mm-yyyy'
        ]
      ]);

So with date the tin turns out at an output. And if you remove
'value'=>($model->date)?date('d-m-Y',strtotime($model->date)):null,

then the date is displayed in the format yyyy-mm-dd because that is how it is stored in the database. The question is how to display the date in the format 'dd-mm-yyyy' ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-07-11
@webinar

As I understand it, you need to change not only value, but also the date
format . So I think you need to take jquery, hook on the initialization event, and if there is "tinny output", replace it with the desired string bypassing the widget Or take a widget with support for choosing an empty date option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question