PHPackages                             mpratt/relativetime - 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. mpratt/relativetime

ActiveLibrary

mpratt/relativetime
===================

A library that calculates the time difference between two dates and returns the result in words (Example: 5 minutes ago or 5 Minutes left). The library supports other languages aswell like Spanish and German.

1.5.13(2y ago)33115.1k—2.3%142MITPHPPHP &gt;=5.3

Since Sep 23Pushed 1y ago2 watchersCompare

[ Source](https://github.com/mpratt/RelativeTime)[ Packagist](https://packagist.org/packages/mpratt/relativetime)[ Docs](https://github.com/mpratt/RelativeTime)[ RSS](/packages/mpratt-relativetime/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (16)Used By (2)

RelativeTime
============

[](#relativetime)

[![Build Status](https://github.com/mpratt/RelativeTime/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/mpratt/RelativeTime/actions)[![Total Downloads](https://camo.githubusercontent.com/1ce5839caa99ab541e71463ae07c162d50ac4242656291e1821473d8f197e7a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d70726174742f72656c617469766574696d652e737667)](https://packagist.org/packages/mpratt/relativetime)[![Monthly Downloads](https://camo.githubusercontent.com/91c0a6362eb4b847eb3c166e2cdd155432c0f4ae0602a20f388ba52b20cb3b1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d70726174742f72656c617469766574696d65)](https://packagist.org/packages/mpratt/relativetime)[![Latest Stable Version](https://camo.githubusercontent.com/188ce47e3d5e945d84fa25273ac1bca47b45187b82c24e98b972a244a64b4ad4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d70726174742f72656c617469766574696d652e737667)](https://packagist.org/packages/mpratt/relativetime)

[![Support via PayPal](https://camo.githubusercontent.com/ab5313818d2a5fd84045bba34cd5e220642f96c1b8cd863a240fc6a181d557c2/68747470733a2f2f63646e2e7261776769742e636f6d2f74776f6c66736f6e2f70617970616c2d6769746875622d627574746f6e2f312e302e302f646973742f627574746f6e2e737667)](https://paypal.me/mtpratt)

RelativeTime is a lightweight and easy to use library that helps you calculate the time difference between two dates and returns the result in words (like, 5 minutes ago or 5 minutes left). The library supports other languages as well like `Spanish`, `PortugueseBR`, `French`, `Czech`, `Russian`, `SimplifiedChinese`, `Swedish` and `German`

It uses the standard \\DateTime() and \\DateInterval() classes found in modern PHP versions. For more information, please read the `Usage` section of this README.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.3 (Tested only on PHP +7.3)

### Installation

[](#installation)

#### Install with Composer

[](#install-with-composer)

If you're using [Composer](https://github.com/composer/composer) to manage dependencies, you can use this library by creating a composer.json file and adding this:

```
{
    "require": {
        "mpratt/relativetime": "~1.0"
    }
}

```

Save it and run `composer.phar install`

#### Standalone Installation (without Composer)

[](#standalone-installation-without-composer)

Download the latest release or clone this repository, place the `Lib/RelativeTime` directory somewhere in your project. Afterwards, you only need to include the included `Autoload.php` file.

```
    require '/path/to/RelativeTime/Autoload.php';

    use RelativeTime\RelativeTime;

    $relativeTime = new RelativeTime();
```

Or if you already have PSR-0 compliant autoloader, you just need to register RelativeTime:

```
    $loader->registerNamespace('RelativeTime', 'path/to/RelativeTime');
```

#### Usage

[](#usage)

Most of the times you are going to need the `convert($fromDate, $toDate)` method.

```
    use RelativeTime\RelativeTime;

    $relativeTime = new RelativeTime();
    echo $relativeTime->convert('2010-09-05', '2010-03-30');
    // 5 months, 6 days ago

    $relativeTime = new RelativeTime();
    echo $relativeTime->convert('2012-03-05', '2013/02/05');
    // 11 months left
```

There are 2 other useful methods `timeAgo($date)` and `timeLeft($date)`, that calculate the time since/until the current date/time.

```
    use RelativeTime\RelativeTime;

    // Asumming Today is the 2013-09-23 17:23:47

    $relativeTime = new RelativeTime();
    echo $relativeTime->timeAgo('2012-08-29 06:00');
    // 1 year, 25 days, 16 hours, 23 minutes, 13 seconds ago

    $relativeTime = new RelativeTime();
    echo $relativeTime->timeLeft('2013-10-31 01:00:05');
    // 1 month, 7 days, 2 hours, 36 minutes, 52 seconds left
```

#### Configuration Options

[](#configuration-options)

The main object accepts an array with configuration directives

```
    use RelativeTime\RelativeTime;

    $config = array(
        'language' => '\RelativeTime\Languages\English',
        'separator' => ', ',
        'suffix' => true,
        'truncate' => 0,
        'use_weeks' => false,
    );

    $relativeTime = new RelativeTime($config);
```

DirectiveDefinitionlanguageThe language to be used, for example `English`, `Spanish`, `PortugueseBR`, `French`, `Czech`, `Russian`, `SimplifiedChinese`, `Swedish` or `German` are supported. Even The instantiated object is allowed, as in `new \RelativeTime\Languages\English()`separatorThe separator between time units. `, ` by default.truncateThe number of units you want to display. By default it displays all of the available ones.suffixWhether or not to append the `.... ago` or `..... left`use\_weeksBy default is set to false. When set to true it will include week numbers too.Author
------

[](#author)

Michael Pratt -  - See also the list of [contributors](https://github.com/mpratt/relativetime/contributors) which participated in this project.

If you like this library, it has been useful to you and want to support me, you can do it via paypal.

[![Support via PayPal](https://camo.githubusercontent.com/ab5313818d2a5fd84045bba34cd5e220642f96c1b8cd863a240fc6a181d557c2/68747470733a2f2f63646e2e7261776769742e636f6d2f74776f6c66736f6e2f70617970616c2d6769746875622d627574746f6e2f312e302e302f646973742f627574746f6e2e737667)](https://paypal.me/mtpratt)

License
-------

[](#license)

RelativeTime is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 70.7% 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 ~252 days

Recently: every ~163 days

Total

15

Last Release

1081d ago

### Community

Maintainers

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

---

Top Contributors

[![mpratt](https://avatars.githubusercontent.com/u/647713?v=4)](https://github.com/mpratt "mpratt (41 commits)")[![wikijm](https://avatars.githubusercontent.com/u/10724809?v=4)](https://github.com/wikijm "wikijm (2 commits)")[![jonathanmaron](https://avatars.githubusercontent.com/u/298462?v=4)](https://github.com/jonathanmaron "jonathanmaron (2 commits)")[![PF94](https://avatars.githubusercontent.com/u/45898787?v=4)](https://github.com/PF94 "PF94 (2 commits)")[![rollerozxa](https://avatars.githubusercontent.com/u/60856959?v=4)](https://github.com/rollerozxa "rollerozxa (2 commits)")[![juniwalk](https://avatars.githubusercontent.com/u/451918?v=4)](https://github.com/juniwalk "juniwalk (1 commits)")[![Langmans](https://avatars.githubusercontent.com/u/756540?v=4)](https://github.com/Langmans "Langmans (1 commits)")[![EricZhang456](https://avatars.githubusercontent.com/u/32814750?v=4)](https://github.com/EricZhang456 "EricZhang456 (1 commits)")[![veselcraft](https://avatars.githubusercontent.com/u/22993408?v=4)](https://github.com/veselcraft "veselcraft (1 commits)")[![2j0ye](https://avatars.githubusercontent.com/u/600299?v=4)](https://github.com/2j0ye "2j0ye (1 commits)")[![sklerotraficon](https://avatars.githubusercontent.com/u/5949123?v=4)](https://github.com/sklerotraficon "sklerotraficon (1 commits)")[![forkiesassds](https://avatars.githubusercontent.com/u/54495659?v=4)](https://github.com/forkiesassds "forkiesassds (1 commits)")[![halfer](https://avatars.githubusercontent.com/u/480975?v=4)](https://github.com/halfer "halfer (1 commits)")[![TheDigitalOrchard](https://avatars.githubusercontent.com/u/3195423?v=4)](https://github.com/TheDigitalOrchard "TheDigitalOrchard (1 commits)")

---

Tags

relativetimedatefutureintervaltime agoago

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mpratt-relativetime/health.svg)

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

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

177661.4M4.8k](/packages/nesbot-carbon)[azuyalabs/yasumi

The easy PHP Library for calculating holidays

1.1k11.4M26](/packages/azuyalabs-yasumi)[carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

218220.4M8](/packages/carbonphp-carbon-doctrine-types)

PHPackages © 2026

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