PHPackages                             detain/php-pretty-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. detain/php-pretty-datetime

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

detain/php-pretty-datetime
==========================

Generates human-readable strings for PHP DateTime objects

1.0.0(7y ago)027[1 PRs](https://github.com/detain/php-pretty-datetime/pulls)MITPHPPHP &gt;=5.3.0

Since Aug 23Pushed 1mo agoCompare

[ Source](https://github.com/detain/php-pretty-datetime)[ Packagist](https://packagist.org/packages/detain/php-pretty-datetime)[ RSS](/packages/detain-php-pretty-datetime/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

php-pretty-datetime
===================

[](#php-pretty-datetime)

Generates human-readable strings for PHP DateTime objects. It handles dates in the past and future. For future dates, it uses the format 'In x unit', ie: 'In 1 minute'. For dates in the past, it uses 'x unit ago', ie: '2 years ago'.

Note: Comparison of dates, for those beyond a day apart, uses the difference between their Unix timestamps.

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

[](#installation)

If you're using Composer to manage dependencies, you can include the following in your composer.json file:

```
"require": {
    "danielstjules/php-pretty-datetime": "~1.0.0"
}

```

Otherwise, you can simply require the file directly:

```
require_once 'path/to/php-pretty-datetime/src/PrettyDateTime.php';
```

Usage
-----

[](#usage)

```
use PrettyDateTime\PrettyDateTime;

PrettyDateTime::parse(new DateTime('now'));         // Moments ago
PrettyDateTime::parse(new DateTime('+ 59 second')); // Seconds from now
PrettyDateTime::parse(new DateTime('+ 1 minute'));  // In 1 minute
PrettyDateTime::parse(new DateTime('- 59 minute')); // 59 minutes ago

// You can supply a secondary argument to provide an alternate reference
// DateTime. The default is the current DateTime, ie: DateTime('now'). In
// addition, it takes into account the day of each DateTime. So in the next
// two examples, even though they're only a second apart, 'Yesterday' and
// 'Tomorrow' will be displayed

$now = new DateTime('1991-05-18 00:00:00 UTC');
$dateTime = new DateTime('1991-05-17 23:59:59 UTC');
PrettyDateTime::parse($dateTime, $now); // Yesterday

$now = new DateTime('1991-05-17 23:59:59 UTC');
$dateTime = new DateTime('1991-05-18 00:00:00 UTC');
PrettyDateTime::parse($dateTime, $now) // Tomorrow
```

Tests
-----

[](#tests)

[![Build Status](https://camo.githubusercontent.com/d4fb2f650f2f000dd6a7f759e110dc50f1243fc8c48338e89d833e8dba18bb1e/68747470733a2f2f7472617669732d63692e6f72672f64616e69656c73746a756c65732f7068702d7072657474792d6461746574696d652e706e67)](https://travis-ci.org/danielstjules/php-pretty-datetime)

From the project directory, tests can be ran using `phpunit`

License
-------

[](#license)

Released under the MIT License - see `LICENSE.txt` for details.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance59

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

2825d ago

### Community

Maintainers

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

---

Top Contributors

[![danielstjules](https://avatars.githubusercontent.com/u/817212?v=4)](https://github.com/danielstjules "danielstjules (20 commits)")[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (5 commits)")[![madwings](https://avatars.githubusercontent.com/u/7276934?v=4)](https://github.com/madwings "madwings (1 commits)")

---

Tags

stringdatetimetimedatereadableprettyhuman

### Embed Badge

![Health badge](/badges/detain-php-pretty-datetime/health.svg)

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

###  Alternatives

[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5791.9k](/packages/danielstjules-php-pretty-datetime)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

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

Date/Calendar recursion library.

5261.0M5](/packages/tplaner-when)[icecave/repr

A library for generating string representations of any value, inspired by Python's reprlib library.

277.1M4](/packages/icecave-repr)

PHPackages © 2026

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