мой валидатор выглядит так:
Код: Выделить всё
protected function validateAttribute($object,$attribute)
{
$a = DateTime::createFromFormat(Yii::app()->locale->getDateFormat('validator'),$object->$attribute);
//Yii::log(print_r($a,true),'custom');
$b = new DateTime($this->pattern);
//Yii::log(print_r($b,true),'custom');
if($a instanceof DateTime)
$d = $b->diff($a);
//Yii::log(print_r($d,true),'custom');
if(isset($d)
&& $d->invert!=0) {
$message=$this->message!==null?$this->message:Yii::t('common','{attribute} must be greater ' . $b->format(Yii::app()->locale->getDateFormat('validator')));
$this->addError($object,$attribute,$message);
}
else if(!isset($d))
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} bad format');
$this->addError($object,$attribute,$message);
}
return;
}