PHPackages                             phrity/datetime - 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. phrity/datetime

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

phrity/datetime
===============

DateTime utilities.

1.1.0(6mo ago)012MITPHPPHP ^8.1CI passing

Since Sep 15Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/sirn-se/phrity-datetime)[ Packagist](https://packagist.org/packages/phrity/datetime)[ Docs](https://phrity.sirn.se/datetime)[ RSS](/packages/phrity-datetime/feed)WikiDiscussions main Synced 3w ago

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

[![Build Status](https://github.com/sirn-se/phrity-datetime/actions/workflows/acceptance.yml/badge.svg)](https://github.com/sirn-se/phrity-datetime/actions)[![Coverage Status](https://camo.githubusercontent.com/7df7f79ef031a3e3bd96195a48667f5b771a5eec3999838310ae81c9937e4ac5/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7369726e2d73652f7068726974792d6461746574696d652f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/sirn-se/phrity-datetime?branch=main)

Introduction
============

[](#introduction)

DateTime utilities.

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

[](#installation)

Install with [Composer](https://getcomposer.org/);

```
composer require phrity/datetime

```

Usage
-----

[](#usage)

Create a range, using two DateTime instances or a DateTime and a DateInterval for relative end date.

```
use Phrity\DateTime\Range;

$start = new DateTime("2023-05-17 13:23");
$end = new DateTime("2023-06-20 23:23");
$now = new DateTime();
$interval = new DateInterval("P15D");
$timezone = new DateTimeZone("+02:00");

$range_1 = new Range($start, $end);
echo "$range_1"; // "2023-05-17T13:23:00+00:00 - 2023-06-20T23:23:00+00:00"
$range_2 = new Range($start, $interval);
echo "$range_2"; // "2023-05-17T13:23:00+00:00 - 2023-06-01T13:23:00+00:00"
```

Basic operations

```
$range_1->getTimezone(); // -> DateTimeZone
$range_1->setTimezone($timezone);

$range_1->getStart(); // -> DateTimeImmutable
$range_1->getEnd(); // -> DateTimeImmutable

$range_1->format("c"); // Format using the same options as for DateTime
```

Modifiers

```
$range_1->add($interval); // Adds interval on start/end of range
$range_1->sub($interval); // Subtracts interval on start/end of range
$range_1->modify("+1 month"); // Modifies start/end of range
```

Checkers

```
$range_1->inRange($now); // If now is within range
$range_1->isBefore($now); // If now is before range
$range_1->isAfter($now); // If now is after range

$range_1->inRange($range_2); // If range_2 is within range_1
$range_1->isBefore($range_2); // If range_2 starts before range_1
$range_1->isAfter($range_2); // If range_2 ends after range_1
```

Intervals and periods

```
$range_1->getInterval(); // -> DateInterval, between start and end
$range_1->getPeriod($interval); // -> DatePeriod, intervals between start and end
```

Versions
--------

[](#versions)

VersionPHP`1.0``^7.4|^8.0`DateTime Range class

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance66

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Total

2

Last Release

200d ago

PHP version history (2 changes)1.0.0PHP ^7.4 | ^8.0

1.1.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4255391?v=4)[Sören Jensen](/maintainers/sirn-se)[@sirn-se](https://github.com/sirn-se)

---

Top Contributors

[![sirn-se](https://avatars.githubusercontent.com/u/4255391?v=4)](https://github.com/sirn-se "sirn-se (10 commits)")

---

Tags

timedaterange

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phrity-datetime/health.svg)

```
[![Health](https://phpackages.com/badges/phrity-datetime/health.svg)](https://phpackages.com/packages/phrity-datetime)
```

###  Alternatives

[league/period

Time range API for PHP

7335.7M22](/packages/league-period)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6239.3M51](/packages/knplabs-knp-time-bundle)[kartik-v/yii2-date-range

An advanced Yii 2 date range picker input for based on bootstrap-daterangepicker plugin.

894.5M42](/packages/kartik-v-yii2-date-range)[brick/date-time

Date and time library

3623.6M94](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

20410.2M16](/packages/aeon-php-calendar)[tplaner/when

Date/Calendar recursion library.

5261.1M7](/packages/tplaner-when)

PHPackages © 2026

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