mrlco / yii2-jalali-datepicker

Yii2 Jalali datepicker is a persian datepicker
BSD 3-Clause "New" or "Revised" License
6 stars 2 forks source link

how to save date in Gregorian #2

Closed thinker-amir closed 4 years ago

thinker-amir commented 7 years ago

hi, we can do save date value in Gregorian format with this datePicker?

mehrna commented 4 years ago

Yeah, you can.

The option calendarType is initially set to 'persian', Just overwrite the default value of that option in clientOptions:


use mrlco\datepicker\Datepicker;

// As a widget
echo Datepicker::widget([
    'model' => $model,
    'attribute' => 'date',
    'template' => '{addon}{input}',
    'clientOptions' => [
        'format' => 'YYYY/MM/DD',
        'calendarType' => 'gregorian' // here we set the calendar
    ]
]);

// within an ActiveForm instance 
$form->field($model, 'date')->widget(
    Datepicker::className(), [
        'inline' => true,
        'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
        'clientOptions' => [
            'format' => 'YYYY/MM/DD',
            'calendarType' => 'gregorian' // here we set the calenda
        ]
]);?>