Working with Dates

Hi, I’m new to Yii and have been working through tutorials and the definitive guide to try to understand how it all works. I like a lot of what I’ve seen, but there are some issues with documentation that make things really hard to figure out.

I decided that after struggling through the blog demo (not up to date with 1.1.2), I would start working on my own sample project. Right away, I’m stuck working with dates. Specifically, I have a table with a date field (not datetime) for ‘birthday’ that’s NOT required. If the field is blank on an update, an exception is raised (‘Incorrect date value: ‘’ for column ‘birthday’ at row 1’) where it is apparently trying to stuff a zero-length string into the date field?? I created a rule to validate the date (after much digging!) and it validates the date if entered properly, however, I still cannot save the record with a blank date. What needs to be done to handle both a blank value and validation of whatever is entered into that field??



In your model which i suppose extends the CActiveRecord class you can override the CActiveRecond::beforeSave() method and do some handling there for more details check the api


Thanks for the suggestion. I guess I didn’t dive far enough into things. The problem I was having was with a basic form where that date field was represented by a text field. After searching further, I have the CJuiDatePicker in place and I no longer have any problems with this date field.