PHPackages                             danoha/date-range - 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. danoha/date-range

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

danoha/date-range
=================

Working with date ranges made easy.

v1.1.0(8y ago)416.4k1MITPHPPHP &gt;=5.6

Since Jun 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Danoha/DateRange)[ Packagist](https://packagist.org/packages/danoha/date-range)[ RSS](/packages/danoha-date-range/feed)WikiDiscussions master Synced 1mo ago

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

DateRange
=========

[](#daterange)

**Working with date ranges made easy.**

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

[](#installation)

Works best with composer. 👌

```
composer require danoha/date-range
```

If you do not use composer or its autoloading, require `src/DateRange.php` and `src/DateRangeCollection.php`.

Then use `\Danoha\DateRange` and `\Danoha\DateRangeCollection` classes directly in your code.

Usage
-----

[](#usage)

Working with date range:

```
$range = new \Danoha\DateRange($from, $to); // any parameter can be NULL
$range
    ->join($thatRange)
    ->intersect([ $from, $to ]) // methods accepting range also accept array
    ->contains($currentDate);
```

Work with date range collection:

```
$coll = new \Danoha\DateRangeCollection([
    [ $from, $to ], // two items per range accepted
    [ 'from' => $from, 'to' => $to, ], // accepted too

    [ $from, NULL, ], // NULL means indefinite interval
    [ NULL, NULL, ], // and can be used on both sides
]);

$coll
    ->join($thatCollection)
    ->intersect([ $range1, $range2 ]) // methods accepting collection also accept array
    ->contains($someRange);
```

To get your ranges back:

```
$coll->getRanges() === [
    new \Danoha\DateRange($from, $to),
    new \Danoha\DateRange($from, NULL),
];

$coll->unwrap() === [
    [ 'from' => $from, 'to' => $to, ], // every range has this exact format
    [ 'from' => $from, 'to' => NULL, ], // regardless of what was passed to constructor
    ...
];
```

Every method that accepts collection also accepts array of ranges (which can be arrays, too):

```
$coll->intersect(
    // another collection
    new \Danoha\DateRangeCollection([ ... ])
);

$coll->intersect([
    // inlined collection (same as constructor)
    [ 'from' => $from, 'to' => $to, ]
]);
```

Note: definite intervals are handled as inclusive on both sides.

Available range methods
-----------------------

[](#available-range-methods)

Note: all methods returning range return new instance. That means calling `$range->join(...)` twice on the same range will create two instances and neither of them will contain both joined ranges.

- getFrom - returns first date in range,
- getTo - returns last date in range,
- unwrap - gets range in array format,
- intersect - finds intersection between current and given range,
- overlaps - tests if current and given range overlap,
- join - finds common range between current and given range,
- isRightAfter - tests if current range is right after given range,
- isRightBefore - tests if current range is right before given range,
- subtract - returns collection of differences between current and given range,
- includes - tests if range includes given date or range,
- includesDate - tests if range includes given date,
- includesRange - tests if range includes given range,
- equals - tests if current range is equal to given range.

Available collection methods
----------------------------

[](#available-collection-methods)

Note: all methods returning collection return new instance. That means calling `$coll->add(...)` twice on the same collection will create two instances and neither of them will contain both added ranges.

- getRanges - gets ranges in current collection,
- unwrap - gets underlying date ranges in array format,
- add - adds given ranges to collection,
- includes - tests if collection includes given date or range,
- join - adds given ranges to current collection and joins ranges in current collection if possible,
- intersect - calculates all intersections with given ranges,
- subtract - subtracts given ranges from current collection.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

3267d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bb060bceaba43c90251af623425e8e9c3a788a147fa7d2bbb2b8f51958f03918?d=identicon)[Danoha](/maintainers/Danoha)

---

Top Contributors

[![Danoha](https://avatars.githubusercontent.com/u/6437793?v=4)](https://github.com/Danoha "Danoha (24 commits)")

---

Tags

composer-librarydate-rangedaterangephp

### Embed Badge

![Health badge](/badges/danoha-date-range/health.svg)

```
[![Health](https://phpackages.com/badges/danoha-date-range/health.svg)](https://phpackages.com/packages/danoha-date-range)
```

###  Alternatives

[wwwision/import-service

Generic service for importing data from different sources to configurable targets such as the Neos Content Repository or an arbitrary database table

1010.9k](/packages/wwwision-import-service)[paxha/laravel-reportable

This Laravel Eloquent extension provides record according to dates using models.

111.2k](/packages/paxha-laravel-reportable)

PHPackages © 2026

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