Yii 1.1: date-compare

Validator to compare two dates, works similarly to CCompareValidator.
15 followers

Yii Date Compare Validator

Validator to compare two dates, works similarly to CCompareValidator.

Model date and datetime validation in PHP and Javascript.

Requirements

Yii 1.1 or above

Install

Extract to your extensions folder.

Alternatively, you can check out from GitHub right in your Git enabled project:

$ git submodule add git@github.com:digitick/yii-date-compare.git extensions/date-compare
$ git submodule init
$ git submodule update

Usage

In your model file:

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    return array(
        // first validate date format
        array('start, end', 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'),
        array('start',
            'ext.date-compare.EDateCompare',
            'compareAttribute' => 'end',
            'operator' => '<',
            'message' => 'Begin date must be before finish date.'
        ),
        array('end',
            'ext.date-compare.EDateCompare',
            'compareAttribute' => 'start',
            'operator' => '>',
            'message' => 'End date must be after begin date.'
        ),
    );
}

Limitations

For now, the only supported format for Javascript validation is ISO format.

The extension doesn't check if a date is correctly formatted (use the built in "date" validator).

Resources

Total 2 comments

#17598 report it
vijay p s at 2014/07/07 08:01am
Doubt!

Hello developer of this article..

 Here in this article why we use the function in the model. we can also use this function in the controller itself?.. is there any logic over this..
#17010 report it
Neminath at 2014/04/24 02:03am
thanks..

it is working........

Leave a comment

Please to leave your comment.

Create extension