0

I am trying to change the default date as first day of previous month in Yii cjuidatepicker. Date is displaying in the textfield correctly,but in the datepicker popup it shows the current date.

Code

 $model_form->suspended_date_from =date("d-M-Y", mktime(0, 0, 0, date("m")-1, 1, date("Y")));
   $date= date('dd-MM-yy', strtotime($model_form->suspended_date_from));
                       $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                            'model' => $model_form,
                            'attribute' => 'suspended_date_from',
                            'htmlOptions' => array(
                                'class' => 'reporttext-field fromdate',
                                'id' => uniqid(),
                            ),
                            'options' => array(

                                'dateFormat' => 'dd-MM-yy',
                               'defaultDate'=> $date,
                                // 'beforeShowDay'=>'unavailable',


                                'showAnim' => 'fade',
                                //'onSelect' => 'js:function( selectedDate ) {$( ".todate" ).datepicker( "option", "minDate", selectedDate );}'
                            ),
                        ));

How can i show it on the datepicker popup??

4

1 回答 1

1

您的日期格式不正确。dd-MM-yy (??) 这个返回类似 1818-AprApr-1313; 所以我认为这是不正确的。如果您将日期格式更改为 dMy,那么您将拥有您想要的。为什么你使用两种不同的日期格式?("d-M-Y" and "d-M-y")

$date= date('d-M-y', strtotime($model_form->suspended_date_from));
                       $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                            'model' => $model_form,
                            'attribute' => 'suspended_date_from',
                            'htmlOptions' => array(
                                'class' => 'reporttext-field fromdate',
                                'id' => uniqid(),
                            ),
                            'options' => array(

                                'dateFormat' => 'd-M-y',
                               'defaultDate'=> $date,
                                // 'beforeShowDay'=>'unavailable',


                                'showAnim' => 'fade',
                                //'onSelect' => 'js:function( selectedDate ) {$( ".todate" ).datepicker( "option", "minDate", selectedDate );}'
                            ),
                        ));

类似的东西对我有用。

于 2013-04-18T07:34:13.097 回答