Search code examples
yii2bootstrap-datetimepickerkartik-v

Yii2 Kartik DateTimePicker start date from far future


I'd like to ask you for support. The yii2 Kartik datetimepicker extension is giving strange and random start date. After clicking the calendar the start date might be year 4678 or year 3599. Imagine scrolling this back to 2017 :) Have you ever faced similar issues. I have checked the forum and I was not able to find the answer.

Here is my code.

<?php
// Usage with model (with no default initial value)
echo $form->field($date, 'start_time')->widget(
   DateTimePicker::className(),
   [
    'size'=>'md',
    'type' => DateTimePicker::TYPE_COMPONENT_APPEND,
    'convertFormat' => true,
    'pluginOptions' => [
        'todayHighlight' => true,
        'todayBtn' => true,
        'format' => 'dd-M-yyyy H:i',
        'autoclose' => true,
        'startDate'=> date('d-m-Y H:i', strtotime(time())),
    ],
   ])->label('Start Date');
?>      

Here is the screen shot of the datetimepicker: https://ibb.co/fu5WFw


Solution

  • The second parameter of date() is a timestamp, so remove strtotime():

    'startDate'=> date('d-m-Y H:i',time()),