Cjuidatepicker Date Format Problem

I am trying to format date correctly using CJuiDatePicker

I wish for the date to be shown in uk format e.g. 31-07-2013 (dd-mm-yyyy)

But I wish for the date to be posted into database using ISO 8601 International Format e.g. 2013-07-13 (yyyy-mm-dd)


		

<?php echo $form->labelEx($model,'fix_date'); ?>

<?php

    $this->widget('zii.widgets.jui.CJuiDatePicker', array(

       'model' => $model,

       'attribute' => 'fix_date',

       'htmlOptions' => array(

       'size' => '10',         // textField size

       'maxlength' => '10',    // textField maxlength

       'dateFormat'=>'yy-mm-dd',

       'altFormat' => 'dd-mm-yy',

    ),

 ));

 ?>

Using the above code, my datepicker inserts the date incorrectly in the view, and also incorrectly into the database:

Hi AhmetS,

"altFormat" option has to be used together with "altField" option.

http://api.jqueryui.com/datepicker/#option-altFormat

I think that it could be a little tricky and cumbersome to use them for your purpose.

I would rather use ‘dd-mm-yy’ format in the client side and do a conversion in the server side.

Thanks for the reply… That is what I am trying to do…

How can I use dd-mm-yy in client side? it always comes up as mm/dd/yy using the datepicker.

Hi AhmetS

‘htmlOptions’ has nothing to date format.

I recommend read some documentation before asking a question.

http://www.yiiframework.com/doc/api/1.1/CJuiDatePicker

You should put your date format inside options instead of htmlOptions.

Example:


<?php echo $form->labelEx($model,'fix_date'); ?>

<?php

    $this->widget('zii.widgets.jui.CJuiDatePicker', array(

       'model' => $model,

       'attribute' => 'fix_date',

        'options'=>array(

            'dateFormat'=>'yy-mm-dd',

        ),

       'htmlOptions' => array(

            'size' => '10',         // textField size

            'maxlength' => '10',    // textField maxlength

    ),

 ));

?>

mirunho got the point.

I didn’t notice that ‘dateFormat’ was in ‘htmlOptions’ …