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

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

swisnl/date-range
=================

A PHP package for manipulating date ranges.

1.1.0(5mo ago)0136MITPHPPHP ^8.2CI passing

Since Aug 15Pushed 1mo agoCompare

[ Source](https://github.com/swisnl/date-range)[ Packagist](https://packagist.org/packages/swisnl/date-range)[ Docs](https://github.com/swisnl/date-range)[ GitHub Sponsors](https://github.com/swisnl)[ RSS](/packages/swisnl-date-range/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (7)Used By (0)

Date Range
==========

[](#date-range)

[![Latest Version on Packagist](https://camo.githubusercontent.com/525abb585c8917baba3f3d1af23c671d884ca5d280c8d13597d4f61b79bfdbfc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f646174652d72616e67652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/date-range)[![Software License](https://camo.githubusercontent.com/cbe927e857a92d608128a52eec4a36a3d2720299ffe875cffa69ef191a0dfe91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737769736e6c2f646174652d72616e67652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Buy us a tree](https://camo.githubusercontent.com/cec0a9b35a1c3235bdbe0d13ea8fbd866a23e30280ad6ca27078c1fd4ac1b709/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/swisnl/date-range)[![Made by SWIS](https://camo.githubusercontent.com/ef6bdd6ab8d4f47bceb74dcf558b0915c6b419cbba320096324af0518e43091d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e7376673f7374796c653d666c61742d737175617265)](https://www.swis.nl)

This PHP package provides classes for immutable objects to represent date ranges and methods to manipulate them.

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

[](#installation)

You can install the package via composer:

```
composer require swisnl/date-range
```

Usage
-----

[](#usage)

`Swis\DateRange\DateRange` is the main class to represent a date range. It is an immutable object that has a start and end date (both optional to support open ended ranges), and provides methods to manipulate the range. Because manipulating date ranges can easily lead to multiple separate date ranges, the package also provides a `Swis\DateRange\DateRangeSet` class to represent a collection of date ranges. This class also provides methods to manipulate set of date ranges. Both classes are immutable, so any manipulation will return a new instance of the class.

```
use Swis\DateRange\DateRange;

$range = DateRange::make('2023-01-01', '2023-01-31');
$range->inRange('2023-01-15'); // true
$range->inRange('2023-02-01'); // false

$range2 = DateRange::make('2023-01-15', '2023-01-20');
$range->overlaps($range2); // true
$range->intersect($range2)->toArray(); // ['2023-01-15', '2023-01-20']
$range->subtract($range2)->toArray(); // [['2023-01-01', '2023-01-14'], ['2023-01-21', '2023-01-31']]

$set = $range->subtract($range2);
$set->addDateRange(DateRange::make('2023-01-10', null)); // [['2023-01-01', null]]
```

For all the available methods, please refer to the PHPDoc documentation in the source code.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/swisnl/date-range/blob/main/CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/swisnl/date-range/blob/main/CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](https://github.com/swisnl/date-range/blob/main/CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Rolf van de Krol](https://github.com/rolfvandekrol)
- [All Contributors](https://github.com/swisnl/date-range/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/swisnl/date-range/blob/main/LICENSE.md) for more information.

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/date-range) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source
-------------------

[](#swis-️-open-source)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance83

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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 ~97 days

Total

2

Last Release

169d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8734305?v=4)[SWIS](/maintainers/swisnl)[@swisnl](https://github.com/swisnl)

![](https://www.gravatar.com/avatar/692b75a6dde1f076e7248f8f35cda5d6b68d993046ac0a08158d49b72b71ba38?d=identicon)[rolfvandekrol](/maintainers/rolfvandekrol)

---

Top Contributors

[![rolfvandekrol](https://avatars.githubusercontent.com/u/434397?v=4)](https://github.com/rolfvandekrol "rolfvandekrol (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[illuminate/support

The Illuminate Support package.

583107.1M34.4k](/packages/illuminate-support)[illuminate/events

The Illuminate Events package.

13454.3M1.7k](/packages/illuminate-events)[illuminate/config

The Illuminate Config package.

10842.7M2.2k](/packages/illuminate-config)[illuminate/pagination

The Illuminate Pagination package.

10532.5M858](/packages/illuminate-pagination)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M177](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.0M314](/packages/illuminate-redis)

PHPackages © 2026

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