Problem With Cjuidatepicker Format

Hi

I have a CJuiDatePicker in my form as follows:


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

    'name' => 'docdata',

    'model' => $model,

    'language' => 'it',

    'options' => array(

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

        'appendText' => ' aaaa-mm-gg',

    ),

));

In the model (after a lot of wasting time using the CDateValidator) I insert this validation rule:


array('docdata', 'type', 'type' => 'date', 'dateFormat' => 'yyyy-MM-dd'),

When I use it in create action it runs correctly.

The problems start in update action. Opening the form, the field “docdata” is filled with “2013-05-28 00:00:00” with all zeroes for time; but I haven’t specified time format and I don’t want it.

Nevertheless, selecting data from the widget, it inserts the date without the time so it runs well; but if I don’t need to change the date, confirming the form after updating other fields, the validation rule says error.

More, if I left the date field empty (in same cases it’s needed) there is no problem in creating record, but in updating it shows “0000-00-00 00:00:00” with the same problem as above.

I tried the solution proposed here by qiang too; it’s good for displaying the date without time in update action, but the date inserted is not saved in the table.

So I need to:

  • show only date without time

  • permit to left empty the field

  • view the field as empty in update action when there is no valid date in it

Can anyone helps me?

No hint to solve the problem?

If you only need the data, change the database column type to DATE instead of DATETIME. There’s no sense introducing a time component if you’re only interested in the date, because you open yourself up to unnecessary time zone complications.

You’re right. It was simpler than I think. Thanks.

Nevertheless I don’t understand why does it show time while specified ‘dateFormat’ => ‘yy-mm-dd’.