Yii Date validation in rules

Here’s how to specify a date validation rules in the Model.

The idea here is that “Date To” should always be greater than “Date From”. Here’s how to do that

public function rules()
   return array(
	array( 'date_to','compare','compareAttribute' => 'date_from','operator'=>'>', 'allowEmpty'=>'false', 'message' => '{attribute} should be greater than "{compareValue}".'),

Piece of cake eh?

Have a happy coding! :)

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>