CJuiDatePicker and null date fields

I am using a CJuiDatePicker on a form to store a date of birth. However when the date of birth is unknown a null value is returned from the database. When i load the form the CJuiDatePicker widget displays 01-01-1970. How do i get this to display nothing in the field??

Thanks

I’m not sure if this is a good practice but I did this:




if ($employee->marriageDate == '0000-00-00')

	$marriageDate = 'None';

else

	$marriageDate = Yii::app()->dateFormatter->formatDateTime($employee->marriageDate,'long', false);



Having the same problem but in a different view, I believe.

I have the datepicker on create/update forms, with the "date" field being optional. At creation, when the "date" is left NULL, it shows as NULL in the DB. However, when I try to update that record, the datepicker shows "0000-00-00" for some reason and I cannot override the default value.

Can anyone help?

Thank you!

EDIT:

Right after posting, I figured it out:


            if (!$model->isNewRecord && $model->date=="0000-00-00"){

                $model->date="";

            }



This will set the "date" field to empty if it returns "0000-00-00" from DB. Hope this helps someone.

You may also check your date attribute before saving it and set it to null if empty, like this:


public function beforeSave() { 

    if ($model->date == "") {

        $model->date = null;

    }

    return parent::beforeSave();

}

I also believe you can set a validation rule in your model and use the allowEmpty property .