Date difference between two dates user seleced and auto display the output in form

   <?= $form->field($model, 'startdate')->widget(DatePicker::classname(), [
                             'type' => DatePicker::TYPE_COMPONENT_PREPEND,`enter code here`
                            'options' => ['placeholder' => 'Sila pilih tarikh mula...'],
                            'pluginOptions' => [
                                'autoclose'=>true,
                                'todayHighlight' => true,
                                'todayBtn' => true,
                                'format' => 'dd/mm/yyyy',
                                ]
                            ]);
                        ?>

                        <?= $form->field($model, 'enddate')->widget(DatePicker::classname(), [
                            'options' => ['placeholder' => 'Sila pilih tarikh akhir...'],
                            'pluginOptions' => [
                                'autoclose'=>true,
                                'todayHighlight' => true,
                                'todayBtn' => true,
                                'format' => 'dd/mm/yyyy',
                                ]
                            ]);
                        ?>

                

<?= $form->field($model, 'totaldays)->textInput(['maxlength' => true]) ?>  
?>

Would you please elaborate your question?

User will select start date and end date from the datepicker in form and it will calculate the difference between two dates and the form will display the result which is number of days by using Yii PHP . I dont how to do the function for calculating the no of days and display the output.

Displaying the output is explained in https://www.yiiframework.com/doc/guide/2.0/en/structure-views. You will likely do the calculation itself in the form model:

class DateDiffModel
{
    public $start;
    public $parsedStart;
    public $end;
    public $parsedEnd;

   public function rules()
   {
        return [
            [['start', 'end'], 'required'],
            [['start'], 'date', 'format'=>'yyyy-M-d', 'timestampAttribute' => 'parsedStart'],
            [['end'], 'date', 'format'=>'yyyy-M-d', 'timestampAttribute' => 'parsedEnd'],
        ];
    }

    public function getDifference()
    {
        return $parsedEnd - $parsedStart;
    }
}

Hello Sir, how to call the function and display the output in form? Can you help me? Im really need this.

I got undefined variable $parseEnd and $parsedStart

I’ve already provided links where it’s explained. Check these please.