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

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

ariyanshipu/laravel-countdown
=============================

Laravel Countdown is a simple and powerful Laravel package that allows you to create and manage countdown timers directly within your application. Whether you're launching a product, running a flash sale, or counting down to an event, this package makes it easy to handle time-sensitive logic in your Laravel projects

v1.0.2(1y ago)12MITPHPPHP &gt;=8.1

Since Apr 12Pushed 1y agoCompare

[ Source](https://github.com/ariyanshiputech/laravel-countdown)[ Packagist](https://packagist.org/packages/ariyanshipu/laravel-countdown)[ Docs](https://github.com/ariyanshiputech/laravel-countdown)[ RSS](/packages/ariyanshipu-laravel-countdown/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

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

[](#laravel-countdown)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c0c9fb20d381404408525ddf3ca59a7423d80fc202cc3a0d9071b0ede9e4d05e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61726979616e73686970752f6c61726176656c2d636f756e74646f776e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ariyanshipu/laravel-countdown/?branch=master)[![Build Status](https://camo.githubusercontent.com/49deec2956c53fd9f1ef7357a8df51099fd8acec0e23d32149507fca69049a26/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61726979616e73686970752f6c61726176656c2d636f756e74646f776e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ariyanshipu/laravel-countdown/build-status/master)

The `ariyanshipu/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 ariyanshipu/laravel-countdown
```

Usage with Laravel Latest Version
---------------------------------

[](#usage-with-laravel-latest-version)

Edit file: `bootstrap/providers.php`

```
    return [
        // ...
        Ariyanshipu\LaravelCountdown\CountdownServiceProvider::class,
        // ...
    ];
```

Edit file: `bootstrap/app.php`

```
    ->withMiddleware(function (Middleware $middleware) {
            $middleware->alias([
                // ...
                    'Countdown' => Ariyanshipu\LaravelCountdown\Facades\CountdownFacade::class,
                // ...
            ]);
        })
```

Usage
-----

[](#usage)

```
use Ariyanshipu\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 Ariyanshipu\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)

- [Ariyan Shipu](https://github.com/ariyanshiputech)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance47

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Total

3

Last Release

395d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

ariyanshipularavel-countdown

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[flarum/core

Delightfully simple forum software.

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

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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