PHPackages                             elfuvo/yii2-date-compare - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. elfuvo/yii2-date-compare

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

elfuvo/yii2-date-compare
========================

Compare dates with the time zone

0.1.2(5y ago)12MITPHPPHP &gt;=7.4.0

Since Feb 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/eLFuvo/yii2-date-compare)[ Packagist](https://packagist.org/packages/elfuvo/yii2-date-compare)[ RSS](/packages/elfuvo-yii2-date-compare/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/00f796b3ed6123e30ca8a5d3a8efe686beb59973780f85bf0b1e7cb6f6d1f1d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f656c6675766f2f796969322d646174652d636f6d706172652e737667)](https://packagist.org/packages/elfuvo/yii2-date-compare)[![Build](https://camo.githubusercontent.com/567a746f751b699a51b5ebd3509a21ec336e5aad049e894710e67d0e12c43fdf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c6675766f2f796969322d646174652d636f6d706172652f4275696c642e737667)](https://github.com/elfuvo/yii2-date-compare)[![Total Downloads](https://camo.githubusercontent.com/b23c298cd758131c68ca32186c46dab00fa27d469e2ec71a4e2e80af73e8a814/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f656c6675766f2f796969322d646174652d636f6d706172652f746f74616c2e737667)](https://packagist.org/packages/elfuvo/yii2-date-compare)[![License](https://camo.githubusercontent.com/0aaf584259a4f29ba920f4044c112258caf6d6d9837be180604fabebe90151c6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f656c6675766f2f796969322d646174652d636f6d706172652e737667)](https://github.com/elfuvo/yii2-date-compare/blob/master/LICENSE)

Requirements
------------

[](#requirements)

- PHP &gt;=7.4

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist elfuvo/yii2-date-compare "~0.1.0"

```

or add

```
"elfuvo/yii2-date-compare": "~0.1.0"

```

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

Configure
---------

[](#configure)

In application configuration file set `defaultTimeZone` (DB time zone) and `timeZone` (application time zone) for formatter

```
    [
        'components' => [
            'formatter' => [
                'class' => \yii\i18n\Formatter::class,
                'defaultTimeZone' => 'UTC', // database timezone
                'timeZone' => 'Europe/Moscow', // application time zone
            ],
        ],
    ];
```

Usage
-----

[](#usage)

Add `DateCompareActiveQueryTrait` to your ActiveQuery class. Then use `where` functions on selection.

```
Custom::find()->andCompareDate('>', Custom::tableName().'.[[createdAt]]', $model->dateFrom);

Custom::find()->orCompareTime('=', Custom::tableName().'.[[createdAt]]', DateConvertHelper::toDefaultTime($model->dateTimeFrom)],
    ['
