PHPackages                             cerbero/date - 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. cerbero/date

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

cerbero/date
============

Framework agnostic and easy to use tool to work with dates.

1.1.4(11y ago)76911MITPHPPHP &gt;=5.4.0

Since Jan 28Pushed 11y ago2 watchersCompare

[ Source](https://github.com/cerbero90/Date)[ Packagist](https://packagist.org/packages/cerbero/date)[ Docs](https://github.com/cerbero90/Date)[ RSS](/packages/cerbero-date/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (9)Used By (1)

Date
====

[](#date)

[![Author](https://camo.githubusercontent.com/73e6f53653e58136b44a6406e113f7d984da8b77f44227e0159538d0a16061db/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406365726265726f39302d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/cerbero90)[![Build Status](https://camo.githubusercontent.com/f6ba7f8cb4efd60080c516452fac292f6f32094e6c41fb98c798acc4b26957b3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6365726265726f39302f446174652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cerbero90/Date)[![Packagist Version](https://camo.githubusercontent.com/fe0c0a176f6a72e89666be43a25d4b0b52b4e6458fb2dff559f0291fcc35e580/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6365726265726f2f646174652e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/cerbero/date)[![Packagist](https://camo.githubusercontent.com/62002c7d634635cc6286e5f047845c1c187a7ea7e76cede454573e7849f37445/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6365726265726f2f646174652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/8fd0a292b53cf44d6f694c129c3ca852a3b6a2ba123bb1328057f77f8a073d91/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6365726265726f39302f446174652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cerbero90/Date)[![Test Coverage](https://camo.githubusercontent.com/f9d45573c0190fa4ec9f6ded5ad68d9fdafdc73d552612a54e9c7f9c30ed91b3/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6769746875622f6365726265726f39302f446174652e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/cerbero90/Date)[![Gratipay](https://camo.githubusercontent.com/61e083b9eab13e783171ad3a7d5708d9e13f82a5c3a47dd2defea5d43bee49b5/68747470733a2f2f696d672e736869656c64732e696f2f67726174697061792f6365726265726f2e7376673f7374796c653d666c61742d737175617265)](https://gratipay.com/cerbero/)

[![SensioLabsInsight](https://camo.githubusercontent.com/c25074c38ba8f3e98c0b3184857a58a2583c998ebb5dbb250b647c65df2ce8e1/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32356166363564362d356563392d343730322d386336382d6534346264633831626561642f6269672e706e67)](https://insight.sensiolabs.com/projects/25af65d6-5ec9-4702-8c68-e44bdc81bead)

Framework agnostic and easy to use tool to work with dates.

One-step installation
---------------------

[](#one-step-installation)

Run the following command from terminal in the root of your project:

```
composer require cerbero/date

```

Preparation
-----------

[](#preparation)

If you are a Laravel user, you may add the following alias in **app/config/app.php** to use this tool everywhere:

```
'aliases' => array(
  'Date' => 'Cerbero\Date',
)
```

Otherwise add this `use` statement on top of the classes where you want to use it:

```
use Cerbero\Date;
```

Usage
-----

[](#usage)

### Create one or more DateTime instances

[](#create-one-or-more-datetime-instances)

Both strings, array and DateTime objects are allowed as parameters. You can also pass unlimited arguments.

It returns one or many DateTime instances depending on the number of given parameters.

```
// pass any English textual date to get an instance of DateTime
$DateTime = Date::create('10 May 2000');

// you can pass an array as argument to create an array of DateTime objects
$array = Date::create(array('now', 'next Thursday'));

// or even unlimited arguments, an array is returned as well
$array = Date::create('2 March 2010', 'now', 'last Tuesday');
```

### Check if a string is a valid date

[](#check-if-a-string-is-a-valid-date)

```
$true = Date::isValid('5 October 1980');

// 13 is recognized as month in English dates, so it's not valid
$false = Date::isValid('13/01/2005');
```

### Format one or more dates

[](#format-one-or-more-dates)

Both strings, array and DateTime objects are allowed as first parameter.

It returns one or many formatted strings depending on the number of given parameters.

```
// '1999-01-30'
$string = Date::format('30 January 1999', 'Y-m-d');

// '1st April, 2014'
$string = Date::format(new DateTime('2014-04-01'), 'jS F, Y');

// array('12/11/10', '01/04/14')
$array = Date::format(array('Nov-12-10', new DateTime('2014-04-01')), 'd/m/y');
```

### Calculate gap between two dates

[](#calculate-gap-between-two-dates)

Both strings and DateTime objects are allowed as parameters. It doesn't matter the order of the dates.

While the `gap()` method returns an array with the gap details, the other methods return an integer:

```
// array('years' => 0, 'months' => 11, 'days' => 30, 'hours' => 14, 'minutes' => 48, 'seconds' => 57)
$array = Date::gap('2000-01-01 09:11:03', '1 January 2001');

// 3600
$int = Date::gapInSeconds('January 1st, 2000', '2000-01-01 01:00:00');

// 60
$int = Date::gapInMinutes(new DateTime('2000-01-01'), '2000-01-01 01:00:00');

// 0
$int = Date::gapInHours('2000-01-01 00:59:00', '2000-01-01 00:00:00');

// 14
$int = Date::gapInDays('last week', 'next week');

// 13
$int = Date::gapInMonths('August 2014', '2013 July');

// 9
$int = Date::gapInYears('5 Jan 2010', new DateTime('2000-02-05'));
```

### Calculate the timestamp of one or more dates

[](#calculate-the-timestamp-of-one-or-more-dates)

Both strings, array and DateTime objects are allowed as parameter.

It returns one or many integer timestamps depending on the number of given parameters.

```
// 1214870400 (GMT)
$int = Date::timestamp('July 1st, 2008');

// 1276560000 (GMT)
$int = Date::timestamp(new DateTime('2010-06-15'));

// array(1214870400, 1276560000) (GMT)
$array = Date::timestamp(array('July 1st, 2008', new DateTime('2010-06-15')), 'd/m/y');
```

### Compare two dates

[](#compare-two-dates)

Both strings and DateTime objects are allowed as parameters. It can compare both despite their type.

```
// check if the first date is Less Than the second one
$false = Date::lt('2007 June', new DateTime('2007-06-01'));

// check if the first date is Less Than or Equals the second one
$true = Date::lte(new DateTime('2007-06-01'), '2007 June');

// check if the first date EQuals the second one
$true = Date::eq('2007 June', new DateTime('2007-06-01'));

// check if the first date does Not EQual the second one
$false = Date::neq(new DateTime('2007-06-01'), '2007 June');

// check if the first date is Greater Than or Equals the second one
$true = Date::gte('2007 June', new DateTime('2007-06-01'));

// check if the first date is Greater Than the second one
$false = Date::gt(new DateTime('2007-06-01'), '2007 June');
```

### Find the earliest date

[](#find-the-earliest-date)

Both strings, array and DateTime objects are allowed as parameters. You can also pass unlimited arguments.

It returns the string or the DateTime instance with the earliest date.

```
// '03/10/1998'
$string = Date::earliest(array('03/10/1998', new DateTime('2006-12-09'), 'yesterday'));

// the DateTime with the date '2009-03-06'
$DateTime = Date::earliest('next Wednesday', new DateTime('2009-03-06'), '19 Nov 2010');
```

### Find the latest date

[](#find-the-latest-date)

Both strings, array and DateTime objects are allowed as parameters. You can also pass unlimited arguments.

It returns the string or the DateTime instance with the latest date.

```
// 'tomorrow'
$string = Date::latest('tomorrow', '10 January 2015', new DateTime('2014-11-04'));

// the DateTime with the date '2016-01-01'
$DateTime = Date::latest(array('last Friday', new DateTime('2016-01-01'), '10/06/80'));
```

### Find all the dates before a date

[](#find-all-the-dates-before-a-date)

Both string and DateTime object are allowed as first parameter.

It returns only strings and DateTime instances passed as second argument with dates before the first parameter.

```
// array(DateTime('2000-09-16'), 'May 1st, 2009')
$array = Date::before('yesterday', array(new DateTime('2000-09-16'), 'tomorrow', 'May 1st, 2009'));

// array(DateTime('2009-03-06'), '19 Nov 2010')
$array = Date::before(new DateTime('2014-01-01'), array(new DateTime('2009-03-06'), '19 Nov 2010', 'July 1st, 2015'));
```

### Find all the dates after a date

[](#find-all-the-dates-after-a-date)

Both string and DateTime object are allowed as first parameter.

It returns only strings and DateTime instances passed as second argument with dates after the first parameter.

```
// array(DateTime('2007-10-28'), 'next Monday')
$array = Date::after('March 1879', array(new DateTime('2007-10-28'), 'next Monday', 'February 1879'));

// array(DateTime('2003-02-14'), 'now')
$array = Date::after(new DateTime('2002-02-20'), array(new DateTime('2003-02-14'), 'now', '12/31/2001'));
```

### Sort dates in ascending order

[](#sort-dates-in-ascending-order)

Both strings, array and DateTime objects are allowed as parameters. You can also pass unlimited arguments.

It returns an array with the strings and DateTime instances sorted in ascending order.

```
// array('Apr-17-1790', 'June 2008', new DateTime('2015-02-01'))
$array = Date::sort('June 2008', new DateTime('2015-02-01'), 'Apr-17-1790');

// array(new DateTime('2014-11-22'), 'yesterday', 'next Wednesday')
$array = Date::sort(array('next Wednesday', new DateTime('2014-11-22'), 'yesterday'));
```

### Sort dates in descending order

[](#sort-dates-in-descending-order)

Both strings, array and DateTime objects are allowed as parameters. You can also pass unlimited arguments.

It returns an array with the strings and DateTime instances sorted in descending order.

```
// array(new DateTime('2015-02-01'), 'June 2008', 'Apr-17-1790')
$array = Date::reverse('June 2008', new DateTime('2015-02-01'), 'Apr-17-1790');

// array('next Wednesday', 'yesterday', new DateTime('2014-11-22'))
$array = Date::reverse(array('next Wednesday', new DateTime('2014-11-22'), 'yesterday'));
```

### Create a range of dates

[](#create-a-range-of-dates)

Both strings and DateTime objects are allowed as first and second parameter. Optionally you can set a step.

It returns an array with all DateTime instances between the starting date and the ending date (included).

```
// array of 22 DateTime instances, from 2008-06-10 to 2008-07-01 included
$array = Date::range('10-June 2008', new DateTime('July 1st, 2008'));

// array of 11 DateTime instances, only even dates from 2008-06-10 to 2008-06-30 included
$array = Date::range('10-June 2008', new DateTime('July 1st, 2008'), 2);
```

### Check if a date is present in an array

[](#check-if-a-date-is-present-in-an-array)

Both strings and DateTime objects are allowed as first parameter.

```
$true = Date::inArray('03/06/09', array(new DateTime('2009-03-06'), '19 Nov 2010'));

$true = Date::inArray(new DateTime('2004-09-21'), array('last week', '21 Sep 2004'));

$false = Date::inArray('now', array('yesterday', 'tomorrow'));
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~19 days

Total

8

Last Release

4093d ago

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

1.0.2PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/596523?v=4)[Matteo Picciolini](/maintainers/cerbero)[@cerbero](https://github.com/cerbero)

---

Tags

datetimedate

### Embed Badge

![Health badge](/badges/cerbero-date/health.svg)

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

###  Alternatives

[league/period

Time range API for PHP

7335.8M24](/packages/league-period)[morilog/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.

9391.3M51](/packages/morilog-jalali)[brick/date-time

Date and time library

3663.8M104](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

20810.4M16](/packages/aeon-php-calendar)[tplaner/when

Date/Calendar recursion library.

5331.1M8](/packages/tplaner-when)[hekmatinasser/verta

This Package helps developers to work with Jalali Datetime class for Laravel Framework PHP

657550.0k28](/packages/hekmatinasser-verta)

PHPackages © 2026

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