Pardon me for a newbie question.
I was wondering when reading the Blog tutorial demo. Why the demo use INTEGER for date field instead of DATE/DATETIME/TIMESTAMP. Is this the best for Yii?
Thank you for any response.
Pardon me for a newbie question.
I was wondering when reading the Blog tutorial demo. Why the demo use INTEGER for date field instead of DATE/DATETIME/TIMESTAMP. Is this the best for Yii?
Thank you for any response.
There is no best type for Yii. Field type should depend on your needs. If you don’t need to perform complex queries to search records by date and you don’t have dates like “1476/05/08”, then INT is ok.
Thank you for prompt reply.
And I supposed it is safe to be used with CJuiDatePicker?
Try a forum search, we’ve had a discussion about this issue already with some pros and cons.
Thank you Mike. I did search the forum, maybe just didnt get the keyword right the first time.
Finally, I found the pros and cons about DATETIME / TIMESTAMP issue. And I decide to keep using DATETIME.
At first my issue was about the data type that I couldnt save my model (getting SQL Error). But apparently I have to check whether the date field is empty or not before I save my model and set it to NULL for empty string.
protected function beforeSave() {
if($this->due_date==''){
$this->setAttribute('due_date', null);
}
return parent::beforeSave();
}