PHPackages                             nepstor/yii2-datetime-compare-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. nepstor/yii2-datetime-compare-validator

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

nepstor/yii2-datetime-compare-validator
=======================================

Yii2 validator for compare datetime.

2.0.3(9y ago)1283.7k↓41.4%17[7 issues](https://github.com/nepstor/yii2-datetime-compare-validator/issues)1BSD-3-ClausePHP

Since Dec 3Pushed 9y ago3 watchersCompare

[ Source](https://github.com/nepstor/yii2-datetime-compare-validator)[ Packagist](https://packagist.org/packages/nepstor/yii2-datetime-compare-validator)[ Docs](https://github.com/nepstor/yii2-datetime-compare-validator)[ RSS](/packages/nepstor-yii2-datetime-compare-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (7)Used By (1)

yii2-datetime-compare-validator
===============================

[](#yii2-datetime-compare-validator)

Validator for yii2 allows you to compare dates.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require nepstor/yii2-datetime-compare-validator "^2.0"
```

or add

```
"nepstor/yii2-datetime-compare-validator": "^2.0"
```

to the require section of your `composer.json` file.

Using
=====

[](#using)

```
public function rules()
{
    return [
        ['begin', nepstor\validators\DateTimeCompareValidator::className(), 'compareAttribute' => 'end', 'format' => 'Y-m-d', 'operator' => '>=']
    ];
}
```

Properties
==========

[](#properties)

This validator compares the specified input datetime with another one and make sure if their relationship is as specified by the operator property.

- `compareAttribute`: the name of the attribute whose value should be compared with.
- `compareValue`: a constant value that the input value should be compared with. When both of this property and `compareAttribute` are specified, this property will take precedence.
- `operator`: the comparison operator. Defaults to `=`. The following operators are supported:
    - `=`: check if two values are equal. The comparison is done is non-strict mode.
    - `!=`: check if two values are NOT equal. The comparison is done is non-strict mode.
    - `>`: check if value being validated is greater than the value being compared with.
    - `>=`: check if value being validated is greater than or equal to the value being compared with.
    - `
