PHPackages                             stesi/yii2-daterange-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. stesi/yii2-daterange-validator

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

stesi/yii2-daterange-validator
==============================

Adds a daterange validator that allows to validate if a model attribute is a valid date range format. Specially usefull if you want to use a DateRangePicker widget and you want to filter by from/until values

v1.2(8y ago)033MITPHP

Since Dec 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/stesi/yii2-daterange-validator)[ Packagist](https://packagist.org/packages/stesi/yii2-daterange-validator)[ RSS](/packages/stesi-yii2-daterange-validator/feed)WikiDiscussions master Synced 2mo ago

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

Yii2-daterange-validator
========================

[](#yii2-daterange-validator)

Daterange validator that allows to validate if a model attribute is a valid date range format. Specially usefull if you want to use a DateRangePicker widget and you want to filter by from/until values

[![Latest Stable Version](https://camo.githubusercontent.com/4a652b1cc1d7f15476f96e5a6176205cff3e7c41ce0af86f82d9e47255c0183a/68747470733a2f2f706f7365722e707567782e6f72672f6e65726275726973682f796969322d6461746572616e67652d76616c696461746f722f762f737461626c65)](https://packagist.org/packages/nerburish/yii2-daterange-validator)[![Total Downloads](https://camo.githubusercontent.com/3b562e8cb1a20addbd24ee5da35f956192328039d5692b17def075f24e356bd3/68747470733a2f2f706f7365722e707567782e6f72672f6e65726275726973682f796969322d6461746572616e67652d76616c696461746f722f646f776e6c6f616473)](https://packagist.org/packages/nerburish/yii2-daterange-validator)[![Latest Unstable Version](https://camo.githubusercontent.com/29f45bc4a1c4492324fbee436e7ace171e67622d0758590527bccd956df6f7de/68747470733a2f2f706f7365722e707567782e6f72672f6e65726275726973682f796969322d6461746572616e67652d76616c696461746f722f762f756e737461626c65)](https://packagist.org/packages/nerburish/yii2-daterange-validator)[![License](https://camo.githubusercontent.com/dbac4e67b750a977bfb1ed01706701c47ad419b34c9117b3cc406f8b11cf6e2f/68747470733a2f2f706f7365722e707567782e6f72672f6e65726275726973682f796969322d6461746572616e67652d76616c696461746f722f6c6963656e7365)](https://packagist.org/packages/nerburish/yii2-daterange-validator)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist nerburish/yii2-daterange-validator "dev-master"

```

or add

```
"nerburish/yii2-daterange-validator": "dev-master"

```

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

Exemple: Filter an attribute model by date range
------------------------------------------------

[](#exemple-filter-an-attribute-model-by-date-range)

Imagine we have a model with a 'created\_at' attribute, and we want to filter that timestamp in our grid by a date range. In our grid we have implemented a field or widget like kartik DateRangePicker (see ) that fills the 'created\_at' input with a date range format Ex: 12/08/2014 to 17/08/2015

We need to go to the search model and add the rule to the model. Then, we must to add the $fromDate and $untilDate attributes to the model;

```
use nerburish\daterangevalidator\DateRangeValidator;

public $fromDate;

public $untilDate;

public function rules()
{
	return [
		[['created_at'], DateRangeValidator::className()]
	];
}

```

If the created\_at value passed to the search model is a valid format range, $fromDate and $untilDate will be assgined with the respective timestamps Then, we could add to the query the next condition:

```
$query->andFilterWhere(['between', 'created_at', $this->fromDate, $this->untilDate]);

```

In case we want to use other attribute names instead defaults, we should pass the attribute names that will be used like this:

```
use nerburish\daterangevalidator\DateRangeValidator;

public $myInitialDateName;

public $myUntilDateName;

public function rules()
{
	return [
		[['created_at'], DateRangeValidator::className(), 'fromDateAttribute' => 'myInitialDateName', 'untilDateAttribute' => 'myUntilDateName']
	];
}

```

By default, it's expected a date format, and this format is taken from the Yii formatter component, but we can define other formats via parameters. Since only date is passed, automatically the from timestamp is set as 00:00:00, and until timestamp is set as 23:59:59. Also, we can change the separator character. Ex: 12-08-2014 / 17-08-2015

```
public function rules()
{
	return [
		[['created_at'], DateRangeValidator::className(), 'format' => 'php:d-m-Y', 'separator' => ' / ']
	];
}

```

However, if we want to directly pass a datetime instead a date format, then we should configure the validator like this:

```
public function rules()
{
	return [
		[['created_at'], DateRangeValidator::className(), 'type' => 'datetime', 'format' => 'php:d/m/Y H:i:s']
	];
}

```

In case we just want validate that the range is a valid range and not assign the from and until timestamp to the attibute model, we can configure the validator of this manner:

```
public function rules()
{
	return [
		[['created_at'], DateRangeValidator::className(), 'setAttributes' => false]
	];
}

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 73.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3080d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d35981376002cdf5be0414c02aec82b5fa59aaad13531658ece24e55b38bb92e?d=identicon)[moccia.f](/maintainers/moccia.f)

---

Top Contributors

[![nerburish](https://avatars.githubusercontent.com/u/5610788?v=4)](https://github.com/nerburish "nerburish (11 commits)")[![stesifrancesco](https://avatars.githubusercontent.com/u/17119418?v=4)](https://github.com/stesifrancesco "stesifrancesco (3 commits)")[![avionwd](https://avatars.githubusercontent.com/u/366848?v=4)](https://github.com/avionwd "avionwd (1 commits)")

---

Tags

validatordateyii2extensiondaterange

### Embed Badge

![Health badge](/badges/stesi-yii2-daterange-validator/health.svg)

```
[![Health](https://phpackages.com/badges/stesi-yii2-daterange-validator/health.svg)](https://phpackages.com/packages/stesi-yii2-daterange-validator)
```

###  Alternatives

[kdn/yii2-domain-validator

Domain name validator for Yii 2.

11122.3k1](/packages/kdn-yii2-domain-validator)[nepstor/yii2-datetime-compare-validator

Yii2 validator for compare datetime.

1283.7k1](/packages/nepstor-yii2-datetime-compare-validator)[codeonyii/yii2-at-least-validator

Validates at least one (or more) attributes.

28253.5k1](/packages/codeonyii-yii2-at-least-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
