We had this problem in our application.
mysql: Y-m-d
yiibooster: m/d/Y
Of course we prefer mysql
format.
We do not want the conversion overload of /
to -
, we want every datetime
in mysql
format.
Since we have many modules and too much date
and datetime
fields in too many forms
, it was not a good practice to force developers to change each of them separately, so we have added these lines in our main layout file:
\Yii::app()->getClientScript()->registerScript("jquery-date-fix",
"
if($.fn.datepicker){
$.fn.datepicker.defaults.format = 'yyyy-mm-dd';
$.fn . datepicker . defaults . autoclose = true;
}
",
\CClientScript::POS_HEAD);
In this way, all the date
and datetime
fields are working with mysql
date format rather than that god damn /
format.
we simply use the widget like:
echo $form->datePickerGroup($manageForm, 'dateOfHire', [
'wrapperHtmlOptions' => [
'class' => 'col-sm-5'
],
'widgetOptions' => [
'options' => [
'startView' => 2,
'changeMonth' => true,
'changeYear' => true,
'yearRange' => "-100:+0",
'language' => 'us',
'autoclose' => true,
'todayHighlight' => true,
],
],
'groupOptions' => [
'class' => 'col-sm-6',
],
'append' => '<label for="' . $manageForm->getId() . '_dateOfHire" class="glyphicon glyphicon-calendar"></label>',
]);
No additional conversion in forms
is needed.