PHPackages                             jpmurray/laravel-countdown - 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. jpmurray/laravel-countdown

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

jpmurray/laravel-countdown
==========================

Provide an easy class easy way to get the time difference between two dates, with an extra bonus trait for eloquent

3.0.0(5y ago)833.8k12[2 issues](https://github.com/jpmurray/laravel-countdown/issues)MITPHPPHP ^7.0CI failing

Since Jul 31Pushed 3y ago2 watchersCompare

[ Source](https://github.com/jpmurray/laravel-countdown)[ Packagist](https://packagist.org/packages/jpmurray/laravel-countdown)[ Docs](https://github.com/jpmurray/laravel-countdown)[ GitHub Sponsors](https://github.com/jpmurray)[ RSS](/packages/jpmurray-laravel-countdown/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (7)Versions (8)Used By (0)

Laravel countdown
=================

[](#laravel-countdown)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0e529d456dda3a72f963d727a009763056a03cb67bce3c2dcc62b852c3b19652/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a706d75727261792f6c61726176656c2d636f756e74646f776e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jpmurray/laravel-countdown/?branch=master)[![Build Status](https://camo.githubusercontent.com/e6a445a01fb795ffb4f83a92282a7e48aa9f493cfeaa36e47be441a62b45353f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a706d75727261792f6c61726176656c2d636f756e74646f776e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jpmurray/laravel-countdown/build-status/master)

The `jpmurray/laravel-countdown` and easy way to get the time difference between two dates, with an extra bonus trait for eloquent.

I needed to get the diffrence of time, and while the [very good Carbon](https://github.com/briannesbitt/carbon) gives me helper to retreive difference in time in different time unit (hours, minutes, etc), there is no method to calculate it all at the same time. Carbon's `diffForHumans` is pretty close, but there is no control over how it displays information, and what information it displays.

Install
-------

[](#install)

You can install this package via composer:

```
$ composer require jpmurray/laravel-countdown
```

Usage with Laravel &lt;= 5.5
----------------------------

[](#usage-with-laravel--55)

You should be using versions of this package that are &lt;= 3.0.0.

If you are using a version of Laravel that doesn't support package autodiscovery, you will have to add the service provider and facade to your `config/app.php` file.

Edit file: `config/app.php`

```
'providers' => [
    // ...
    jpmurray\LaravelCountdown\CountdownServiceProvider::class,
    // ...
];

// ...

'aliases' => [
    // ...
    'Countdown' => jpmurray\LaravelCountdown\Facades\CountdownFacade::class,
    // ...
];
```

Usage
-----

[](#usage)

```
use jpmurray\LaravelCountdown\Countdown;

// To get time from 5 years ago until now, you can do the following.
// Note that you can send a string to the from and to methods, we will
// try to parse it with Carbon behind the scene
$now = Carbon::now();

$countdown = Countdown::from($now->copy()->subYears(5))
                        ->to($now)->get();

// The above will return the Countdown class where you can access the following values.
// Those mean that from 5 years ago to now, there is 5 years, 1 week, 1 day, 2 hours 15 minutes and 23 seconds

$countdown->years; // 5
$countdown->weeks; // 1
$countdown->days; // 1
$countdown->hours; // 2
$countdown->minutes; // 15
$countdown->seconds; // 23

// It will of course, also work in reverse order of time.
// This will get the time between now and some future date
$countdown = Countdown::from($now)
             ->to($now->copy()->addYears(5))
             ->get();

// To return to humans string
$countdown->toHuman(); // 18 years, 33 weeks, 2 days, 18 hours, 4 minutes and 35 seconds

// You to can pass custom string to parse in method toHuman, like this:
$countdown->toHuman('{days} days, {hours} hours and {minutes} minutes'); // 2 days, 18 hours, 4 minutes
```

Eloquent Trait
--------------

[](#eloquent-trait)

```
// For convenience, we provide a trait that you can add to any model in your Laravel app that provides
// quick methods to get the values of time between dates. For example:

use jpmurray\LaravelCountdown\Traits\CalculateTimeDiff;

class User extends Authenticatable
{
    use Notifiable, CalculateTimeDiff;
    //...
}
```

#### Example to use Trait:

[](#example-to-use-trait)

```
// This enables the following:
// You should have casted your attributes to dates beforehand
$user = User::find(1);
$user->elapsed('trial_ends_at'); // get the time elapsed between the date in attribute trial_ends_at to now
$user->until('trial_ends_at'); // get the time from now until the date in attribute trial_ends_at
```

Tests
-----

[](#tests)

```
composer run test
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](changelog.MD) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Jean-Philippe Murray](https://github.com/jpmurray)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 67.8% 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 ~199 days

Recently: every ~299 days

Total

7

Last Release

2013d ago

Major Versions

1.3.0 → 2.0.02020-04-07

2.0.0 → 3.0.02020-11-08

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1550428?v=4)[Jean-Philippe Murray](/maintainers/jpmurray)[@jpmurray](https://github.com/jpmurray)

---

Top Contributors

[![jpmurray](https://avatars.githubusercontent.com/u/1550428?v=4)](https://github.com/jpmurray "jpmurray (40 commits)")[![juniorb2ss](https://avatars.githubusercontent.com/u/3980385?v=4)](https://github.com/juniorb2ss "juniorb2ss (17 commits)")[![ConsoleTVs](https://avatars.githubusercontent.com/u/6124435?v=4)](https://github.com/ConsoleTVs "ConsoleTVs (1 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (1 commits)")

---

Tags

hacktoberfesttimedatescountdownjpmurrayelapseduntil

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jpmurray-laravel-countdown/health.svg)

```
[![Health](https://phpackages.com/badges/jpmurray-laravel-countdown/health.svg)](https://phpackages.com/packages/jpmurray-laravel-countdown)
```

###  Alternatives

[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[benhall14/php-calendar

A simple PHP class to generate calendars.

9822.6k](/packages/benhall14-php-calendar)[wilianx7/php-recurring

PHP library to make getting dates easier when working with recurring tasks.

1045.0k](/packages/wilianx7-php-recurring)

PHPackages © 2026

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