PHPackages                             bayfrontmedia/php-time-helpers - 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. bayfrontmedia/php-time-helpers

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

bayfrontmedia/php-time-helpers
==============================

Helper class to provide useful time related functions.

v2.3.0(6mo ago)01.4k2MITPHPPHP ^8.0

Since Jul 27Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/bayfrontmedia/php-time-helpers)[ Packagist](https://packagist.org/packages/bayfrontmedia/php-time-helpers)[ Docs](https://github.com/bayfrontmedia/php-time-helpers)[ RSS](/packages/bayfrontmedia-php-time-helpers/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (2)

PHP time helpers
----------------

[](#php-time-helpers)

Helper class to provide useful time related functions.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)

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

[](#installation)

```
composer require bayfrontmedia/php-time-helpers

```

Usage
-----

[](#usage)

- [getReadTime](#getreadtime)
- [getDateTime](#getdatetime)
- [isLeapYear](#isleapyear)
- [humanArray](#humanarray)
- [human](#human)
- [toIso8601](#toiso8601)
- [toTimezone](#totimezone)
- [isTimezone](#istimezone)
- [isFormat](#isformat)
- [inPast](#inpast)
- [inFuture](#infuture)
- [isBefore](#isbefore)
- [isAfter](#isafter)
- [stopwatch](#stopwatch)
- [isWeekday](#isweekday)
- [isWeekend](#isweekend)
- [getRandomDate](#getrandomdate)
- [lastMonday](#lastmonday)
- [lastTuesday](#lasttuesday)
- [lastWednesday](#lastwednesday)
- [lastThursday](#lastthursday)
- [lastFriday](#lastfriday)
- [lastSaturday](#lastsaturday)
- [lastSunday](#lastsunday)
- [nextMonday](#nextmonday)
- [nextTuesday](#nexttuesday)
- [nextWednesday](#nextwednesday)
- [nextThursday](#nextthursday)
- [nextFriday](#nextfriday)
- [nextSaturday](#nextsaturday)
- [nextSunday](#nextsunday)

---

### getReadTime

[](#getreadtime)

**Description:**

Get estimated minutes necessary to read content, based on reading a given amount of words per minute (WPM).

**Parameters:**

- `$content` (string)
- `$wpm = 180` (int)

**Returns:**

- (int)

**Example:**

```
use Bayfront\TimeHelpers\Time;

$content = 'This is a string of content.';

echo Time::getReadTime($content);

```

---

### getDateTime

[](#getdatetime)

**Description:**

Returns datetime of a given timestamp, or current time (default).

**Parameters:**

- `$timestamp = NULL` (int|null)

**Returns:**

- (string)

**Example:**

```
use Bayfront\TimeHelpers\Time;

echo Time::getDateTime();

```

---

### isLeapYear

[](#isleapyear)

**Description:**

Checks if a given year is a leap year, using current year by default.

**Parameters:**

- `$year = NULL` (int|null): Four digit year, PHP `date('Y')` format

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

if (Time::isLeapYear()) {
    // Do something
}

```

---

### humanArray

[](#humanarray)

**Description:**

Returns human time as an array.

**NOTE:** Due to discrepancies between the length of certain months and years (ie: leap year), elapsed time calculations for these units of time are approximate (30 days per month, 365 days per year).

**Parameters:**

- `$time_start` (int): Timestamp of starting time
- `$time_end` (int): Timestamp of ending time
- `$limit = 'year'` (string): Limit of time duration to calculate
- `$language = NULL` (array|null): Custom language to return

Valid `$limit` values are:

- `year`
- `month`
- `week`
- `day`
- `hour`
- `minute`
- `second`

Passing a `$language` array allows you to translate the words returned by this method. The array keys must match those of the default array, which is:

```
$language = [
    'year' => 'year',
    'years' => 'years',
    'month' => 'month',
    'months' => 'months',
    'week' => 'week',
    'weeks' => 'weeks',
    'day' => 'day',
    'days' => 'days',
    'hour' => 'hour',
    'hours' => 'hours',
    'minute' => 'minute',
    'minutes' => 'minutes',
    'second' => 'second',
    'seconds' => 'seconds',
    'past' => 'ago',
    'present' => 'just now',
    'future' => 'to go'
];

```

**Returns:**

- (array)

#### Example:

[](#example)

```
use Bayfront\TimeHelpers\Time;

$start = time();
$end = time() + 51001;

print_r(Time::humanArray($start, $end, 'minute'));

```

---

### human

[](#human)

**Description:**

Returns human time as a string.

For more information, see [humanArray](#humanarray).

**Parameters:**

- `$time_start` (int): Timestamp of starting time
- `$time_end` (int): Timestamp of ending time
- `$limit = 'year'` (string): Limit of time duration to calculate
- `$language = NULL` (array| null): Custom language to return

**Returns:**

- (string)

**Example:**

```
use Bayfront\TimeHelpers\Time;

$start = time();
$end = time() + 51001;

echo Time::human($start, $end);

```

---

### toIso8601

[](#toiso8601)

**Description:**

Convert UTC datetime to ISO-8601 format.

**Parameters:**

- `$datetime` (int|string): Any valid date/time formatted string or timestamp

**Returns:**

- (string)

---

### toTimezone

[](#totimezone)

**Description:**

Convert UTC datetime to format using timezone.

See:

**Parameters:**

- `$datetime` (int|string): Any valid date/time formatted string or timestamp
- `$timezone` (string): Any valid timezone identifier
- `$format = 'U'` (string): Any valid date/time format

**Returns:**

- (string)

---

### isTimezone

[](#istimezone)

**Description:**

Checks if string is a valid timezone identifier.

See:

**Parameters:**

- `$timezone` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

if (Time::isTimezone('America/New_York')) {
    // Do something
}

```

---

### isFormat

[](#isformat)

**Description:**

Checks if value is a given dateTime format.

See:

**Parameters:**

- `$date` (string)
- `$format` (string): Any valid date/time format
- `$strict = 'true'` (bool)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

$date = '2020-07-18';

if (Time::isFormat($date, 'Y-m-d')) {
    // Do something
}

```

---

### inPast

[](#inpast)

**Description:**

Checks if date/time is in the past.

See:

**Parameters:**

- `$date` (string): Any valid date/time format

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

if (Time::inPast('last Tuesday')) {
    // Do something
}

```

---

### inFuture

[](#infuture)

**Description:**

Checks if date/time is in the future.

See:

**Parameters:**

- `$date` (string): Any valid date/time format

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

if (Time::inFuture('2050-12-31')) {
    // Do something
}

```

---

### isBefore

[](#isbefore)

**Description:**

Checks if date/time is before a given date/time.

See:

**Parameters:**

- `$date` (string): Any valid date/time format
- `$before` (string): Any valid date/time format

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

if (Time::isBefore('today', '2050-12-31')) {
    // Do something
}

```

---

### isAfter

[](#isafter)

**Description:**

Checks if date/time is after a given date/time.

See:

**Parameters:**

- `$date` (string): Any valid date/time format
- `$after` (string): Any valid date/time format

**Returns:**

- (bool)

**Example:**

```
use Bayfront\TimeHelpers\Time;

if (Time::isAfter('today', '2050-12-31')) {
    // Do something
}

```

---

### stopwatch

[](#stopwatch)

**Description:**

Return the amount of time (in seconds) the callback took to execute.

**Parameters:**

- `$callable` (callback)
- `$times = 1` (int): Number of times to iterate the callback
- `$decimals = 5` (int): Number of decimal places to round to

**Returns:**

- (float)

**Example:**

```
use Bayfront\TimeHelpers\Time;

$elapsed = Time::stopwatch(function() {

    sleep(2);

}, 2);

```

---

### isWeekday

[](#isweekday)

**Description:**

Is date a weekday?

**Parameters:**

- `$date` (string): Any valid date/time format

**Returns:**

- (bool)

---

### isWeekend

[](#isweekend)

**Description:**

Is date a weekend?

**Parameters:**

- `$date` (string): Any valid date/time format

**Returns:**

- (bool)

---

### getRandomDate

[](#getrandomdate)

**Description:**

Get random date between two dates.

**Parameters:**

- `$start_date = '1900-01-01` (string): Any valid date/time format
- `$end_date = null` (string|null): Any valid date/time format. If `null`, the current date will be used
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned

**Returns:**

- (string)

---

### lastMonday

[](#lastmonday)

**Description:**

Get date of the previous occurring Monday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Monday

**Returns:**

- (string)

---

### lastTuesday

[](#lasttuesday)

**Description:**

Get date of the previous occurring Tuesday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Tuesday

**Returns:**

- (string)

---

### lastWednesday

[](#lastwednesday)

**Description:**

Get date of the previous occurring Wednesday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Wednesday

**Returns:**

- (string)

---

### lastThursday

[](#lastthursday)

**Description:**

Get date of the previous occurring Thursday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Thursday

**Returns:**

- (string)

---

### lastFriday

[](#lastfriday)

**Description:**

Get date of the previous occurring Friday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Friday

**Returns:**

- (string)

---

### lastSaturday

[](#lastsaturday)

**Description:**

Get date of the previous occurring Saturday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Saturday

**Returns:**

- (string)

---

### lastSunday

[](#lastsunday)

**Description:**

Get date of the previous occurring Sunday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Sunday

**Returns:**

- (string)

---

### nextMonday

[](#nextmonday)

**Description:**

Get date of the next occurring Monday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Monday

**Returns:**

- (string)

---

### nextTuesday

[](#nexttuesday)

**Description:**

Get date of the next occurring Tuesday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Tuesday

**Returns:**

- (string)

---

### nextWednesday

[](#nextwednesday)

**Description:**

Get date of the next occurring Wednesday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Wednesday

**Returns:**

- (string)

---

### nextThursday

[](#nextthursday)

**Description:**

Get date of the next occurring Thursday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Thursday

**Returns:**

- (string)

---

### nextFriday

[](#nextfriday)

**Description:**

Get date of the next occurring Friday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Friday

**Returns:**

- (string)

---

### nextSaturday

[](#nextsaturday)

**Description:**

Get date of the next occurring Saturday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Saturday

**Returns:**

- (string)

---

### nextSunday

[](#nextsunday)

**Description:**

Get date of the next occurring Sunday from a given date.

**Parameters:**

- `$date` (string): Any valid date/time format
- `$format = 'Y-m-d H:i:s'` (string): Date format to be returned
- `$include_self = true` (bool): If true, the current date will be returned if it falls on a Sunday

**Returns:**

- (string)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance67

Regular maintenance activity

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

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

Recently: every ~253 days

Total

8

Last Release

193d ago

Major Versions

v1.1.1 → v2.0.02023-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

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

---

Tags

datedatetimeelapsedhumanphptimephpdatetimetimedatehumanelapsed

### Embed Badge

![Health badge](/badges/bayfrontmedia-php-time-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/bayfrontmedia-php-time-helpers/health.svg)](https://phpackages.com/packages/bayfrontmedia-php-time-helpers)
```

###  Alternatives

[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.5M3](/packages/kartik-v-php-date-formatter)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14282.3k](/packages/dater-dater)[zjkal/time-helper

一个简单快捷的PHP日期时间助手类库。 a smart PHP datetime helper library.

21128.6k1](/packages/zjkal-time-helper)[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5791.9k](/packages/danielstjules-php-pretty-datetime)[maherelgamil/arabicdatetime

Easy and useful tool to generate arabic or hijri date with multi-language support for laravel

414.5k](/packages/maherelgamil-arabicdatetime)

PHPackages © 2026

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