PHPackages                             philiprehberger/php-human-duration - 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. philiprehberger/php-human-duration

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

philiprehberger/php-human-duration
==================================

Convert seconds into human-readable duration strings

v1.2.0(2mo ago)138MITPHPPHP ^8.2CI passing

Since Mar 13Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/php-human-duration)[ Packagist](https://packagist.org/packages/philiprehberger/php-human-duration)[ Docs](https://github.com/philiprehberger/php-human-duration)[ GitHub Sponsors](https://github.com/philiprehberger)[ RSS](/packages/philiprehberger-php-human-duration/feed)WikiDiscussions main Synced 3w ago

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

PHP Human Duration
==================

[](#php-human-duration)

[![Tests](https://github.com/philiprehberger/php-human-duration/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-human-duration/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/3cb1abb7393643d85268c552f7fa5284ae9a4b03f8d2b3427fcec5f0c0567f51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d68756d616e2d6475726174696f6e2e737667)](https://packagist.org/packages/philiprehberger/php-human-duration)[![Last updated](https://camo.githubusercontent.com/779d5b4f505ba7f3e544aff64e8cd8e7631f1f4ecafa787900fc7d209a9a802a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f7068702d68756d616e2d6475726174696f6e)](https://github.com/philiprehberger/php-human-duration/commits/main)

Convert seconds into human-readable duration strings.

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

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require philiprehberger/php-human-duration
```

Usage
-----

[](#usage)

### Creating Durations

[](#creating-durations)

```
use PhilipRehberger\HumanDuration\Duration;

// From seconds
$duration = Duration::fromSeconds(3665);

// From minutes
$duration = Duration::fromMinutes(90);

// From hours
$duration = Duration::fromHours(2.5);

// From the difference between two dates
$duration = Duration::between(
    new DateTimeImmutable('2026-01-01 08:00:00'),
    new DateTimeImmutable('2026-01-01 09:30:00'),
);
```

### Parsing Durations

[](#parsing-durations)

```
use PhilipRehberger\HumanDuration\Duration;

// Shorthand
$duration = Duration::parse('1h 30m 15s'); // 5415 seconds

// Verbose
$duration = Duration::parse('2 hours, 45 minutes'); // 9900 seconds

// Decimal
$duration = Duration::parse('1.5h'); // 5400 seconds

// With days
$duration = Duration::parse('1d 2h'); // 93600 seconds

// ISO 8601
$duration = Duration::fromIso('PT1H30M15S'); // 5415 seconds
$duration = Duration::fromIso('P1DT2H');     // 93600 seconds

// Convert to ISO 8601
$duration->toIso(); // "PT1H30M15S"
```

### Formatting Durations

[](#formatting-durations)

```
$duration = Duration::fromSeconds(3665);

$duration->toHuman();   // "1h 1m 5s"
$duration->toVerbose(); // "1 hour, 1 minute, 5 seconds"
$duration->toCompact(); // "1:01:05"

// Stringable — casting to string uses toHuman()
echo $duration; // "1h 1m 5s"
```

### Accessing Raw Values

[](#accessing-raw-values)

```
$duration = Duration::fromSeconds(5400);

$duration->totalSeconds(); // 5400
$duration->totalMinutes(); // 90.0
$duration->totalHours();   // 1.5
```

### Comparing and Combining Durations

[](#comparing-and-combining-durations)

```
$a = Duration::fromMinutes(90);
$b = Duration::fromHours(1);

$a->isGreaterThan($b); // true
$a->isLessThan($b);    // false
$a->equals($b);        // false

$a->add($b)->toHuman();      // "2h 30m"
$a->subtract($b)->toHuman(); // "30m"
```

### Proportional Calculations

[](#proportional-calculations)

```
$duration = Duration::fromMinutes(90);

// Get 25% of a duration
$quarter = $duration->percentage(25);
$quarter->totalSeconds(); // 1350 (22.5 minutes)

// Get a fraction of a duration
$third = $duration->fraction(1, 3);
$third->totalSeconds(); // 1800 (30 minutes)
```

### Negative Durations

[](#negative-durations)

```
$duration = Duration::fromSeconds(-65);

$duration->toHuman();   // "-1m 5s"
$duration->toVerbose(); // "-1 minute, 5 seconds"
$duration->toCompact(); // "-1:05"
```

API
---

[](#api)

MethodReturnDescription`Duration::fromSeconds(int $seconds)``Duration`Create from seconds`Duration::fromMinutes(int|float $minutes)``Duration`Create from minutes`Duration::fromHours(int|float $hours)``Duration`Create from hours`Duration::between(DateTimeInterface $start, DateTimeInterface $end)``Duration`Create from date difference`Duration::parse(string $input)``Duration`Parse human-readable string (e.g., "1h 30m", "2 hours")`Duration::fromIso(string $iso)``Duration`Parse ISO 8601 duration (e.g., "PT1H30M")`toHuman()``string`Compact format: `1h 5m 30s``toVerbose()``string`Verbose format: `1 hour, 5 minutes, 30 seconds``toCompact()``string`Clock format: `1:05:30``toIso()``string`ISO 8601 format: `PT1H5M30S``totalSeconds()``int`Total seconds`totalMinutes()``float`Total minutes`totalHours()``float`Total hours`totalDays()``float`Total days`isGreaterThan(Duration $other)``bool`Check if greater than another duration`isLessThan(Duration $other)``bool`Check if less than another duration`equals(Duration $other)``bool`Check if equal to another duration`add(Duration $other)``Duration`Add two durations, returning a new instance`subtract(Duration $other)``Duration`Subtract a duration, returning a new instance`percentage(float $percent)``Duration`Return given percentage of this duration`fraction(int $numerator, int $denominator)``Duration`Return proportional fraction of this durationDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

Support
-------

[](#support)

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/php-human-duration)

🐛 [Report issues](https://github.com/philiprehberger/php-human-duration/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/php-human-duration/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance88

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.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

Every ~4 days

Total

5

Last Release

86d ago

### Community

Maintainers

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

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

formattimereadabledurationhuman

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-human-duration/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-php-human-duration/health.svg)](https://phpackages.com/packages/philiprehberger-php-human-duration)
```

###  Alternatives

[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6239.3M51](/packages/knplabs-knp-time-bundle)[brick/date-time

Date and time library

3623.6M94](/packages/brick-date-time)[khill/php-duration

Converts between colon formatted time, human-readable time and seconds

1571.8M20](/packages/khill-php-duration)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1821.1M18](/packages/consistence-consistence)[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5797.0k](/packages/danielstjules-php-pretty-datetime)[sybio/gif-frame-extractor

PHP class that separates all the frames (and their duration) of an animated GIF

179431.1k9](/packages/sybio-gif-frame-extractor)

PHPackages © 2026

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