PHPackages                             salernolabs/relative-time - 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. salernolabs/relative-time

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

salernolabs/relative-time
=========================

Library for building relative time strings in PHP.

v1.0.0(6y ago)04.0k↑122.2%MITPHPPHP &gt;=7.2

Since Apr 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/salernolabs/relative-time)[ Packagist](https://packagist.org/packages/salernolabs/relative-time)[ Docs](http://www.salernolabs.com/)[ RSS](/packages/salernolabs-relative-time/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

salernolabs/relative-time
=========================

[](#salernolabsrelative-time)

[![Latest Stable Version](https://camo.githubusercontent.com/5996ab0bc4242610a09a3c99a2821767a6a5820a6d602a2cd2166d40602a1cfb/68747470733a2f2f706f7365722e707567782e6f72672f73616c65726e6f6c6162732f72656c61746976652d74696d652f762f737461626c65)](https://packagist.org/packages/salernolabs/relative-time)[![License](https://camo.githubusercontent.com/09e455368abcdc6f1c27588c12b19d81ade7b32c3f3e157a892fe79be6f5b41a/68747470733a2f2f706f7365722e707567782e6f72672f73616c65726e6f6c6162732f72656c61746976652d74696d652f6c6963656e7365)](https://packagist.org/packages/salernolabs/relative-time)[![Build Status](https://camo.githubusercontent.com/4f9c473afbf757f989f380ec1ad1e651fafac6f41934a341a60835aa77b4f62f/68747470733a2f2f7472617669732d63692e636f6d2f73616c65726e6f6c6162732f72656c61746976652d74696d652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/salernolabs/relative-time)

Library for building relative time strings in PHP.

Usage
-----

[](#usage)

### Installation

[](#installation)

First include this project with composer

```
composer require salernolabs/relative-time

```

### Formatting Time

[](#formatting-time)

Then run the formatter on a DateTime object.

```
$formatter = new \SalernoLabs\RelativeTime\Formatter();
$relativeTime = $formatter->getRelativeTime(new \DateTime('-47 minutes'));
echo $relativeTime;

```

This would output '47 minutes ago'. The formatter will also go forward as well so if you put in '+47 minutes' it will say "47 mintues from now".

#### Examples of Time Reformatting

[](#examples-of-time-reformatting)

This library will also give short-hand conversational outputs for some values. For example:

Time ModificationOutput-5 minutesjust now+5 minutesmomentarily-1 minuteabout a minute ago+1 minuteabout a minute from now-1 hourabout an hour ago+1 hourabout an hour from now-1 dayyesterday+1 daytomorrowAnd actual numbers for other times, for example:

Time ModificationOutput-45 seconds45 seconds ago-45 minutes45 minutes ago-7 hours7 hours ago-3 years3 years ago#### HTML5 Tags

[](#html5-tags)

You can easily wrap the output in an html5 time tag by using the getRelativeTimeTag function.

```
$formatter = new \SalernoLabs\RelativeTime\Formatter();
$relativeTime = $formatter->getRelativeTimeTag(new \DateTime('-47 minutes'));
echo $relativeTime;

```

This would output:

```
47 minutes ago

```

### Relative Time Clock

[](#relative-time-clock)

The relative time clock can give you a textual representation of a time of day.

```
$clock = new \SalernoLabs\RelativeTime\Clock();

$time = $clock
    ->setTime(new \DateTime('7:47'))
    ->getTime();

echo $time; // a quarter to eight o'clock

```

#### Examples of Relative Clock Output

[](#examples-of-relative-clock-output)

Input TimeOutput1:00one o'clock5:03five o'clock,2:07almost ten after two o'clock,3:10ten after three o'clock4:15quarter after four o'clock6:22almost half past six o'clock7:32half past seven o'clock8:44almost a quarter to nine o'clock9:45a quarter to ten o'clock11:55almost twelve o'clock12:00twelve o'clock,12:59almost one o'clock12:45a quarter to one o'clock12:43almost a quarter to one o'clock

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Total

5

Last Release

2480d ago

Major Versions

0.2.1 → v1.0.02019-08-03

PHP version history (2 changes)0.1.0PHP &gt;=5.4

v1.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/155974?v=4)[Eric Salerno](/maintainers/ericsalerno)[@ericsalerno](https://github.com/ericsalerno)

---

Top Contributors

[![ericsalerno](https://avatars.githubusercontent.com/u/155974?v=4)](https://github.com/ericsalerno "ericsalerno (3 commits)")

---

Tags

clockformatterhtmlphprelativetimephptimestamprelative-time

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/salernolabs-relative-time/health.svg)

```
[![Health](https://phpackages.com/badges/salernolabs-relative-time/health.svg)](https://phpackages.com/packages/salernolabs-relative-time)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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