I reached to a solution that can be used with MySQL for all different date formats. I hope this can help others.
It is a suggestion that can be improved for reusability, for sure.
Suppose that you have a 'mydate' field in your AR. So, add the following lines to your AR:
// convert input date to mysql date format
protected function beforeSave(){
$this->mydate = date('Y-m-d', CDateTimeParser::parse($this->mydate, Yii::app()->locale->dateFormat));
return true;
}
/* when loading records, reconvert date from mysql format to your locale format.
NOTE: this method converts just to a date format, not datetime format.
I don't know how to differentiate them.
*/
protected function afterFind(){
$this->mydate = Yii::app()->dateFormatter->formatDateTime(
CDateTimeParser::parse($this->mydate, 'yyyy-MM-dd'),'medium',null);
return true;
}
// rule to validate date according to locale date format
public function rules(){
return array(
array('mydate', 'type', 'type'=>'date', 'dateFormat'=>Yii::app()->locale->dateFormat),
);
}
Really long line codes, but I am thinking we can extend CAtiveRecord to catch all date fields and do the conversions.
Any problems or doubts, please advice. Improvements and new ideas are welcome.

Help
















