PHPackages                             twipsi/chronos - 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. twipsi/chronos

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

twipsi/chronos
==============

Provides a simplified interface to play with time

1.0.0(3y ago)041BSD-3-ClausePHPPHP &gt;=8.1

Since Oct 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Twipsi/chronos)[ Packagist](https://packagist.org/packages/twipsi/chronos)[ Docs](http://www.github.com/twipsi/chronos)[ RSS](/packages/twipsi-chronos/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Chronos
=======

[](#chronos)

Simple class to play with time

Install
-------

[](#install)

```
composer require twipsi/chronos

```

Initializing the class
----------------------

[](#initializing-the-class)

You can set the initial date as a DateTime object or a Chronos instance or a valid date string or a timestamp.

```
Chronos::date(new Chronos)...
Chronos::date(new DateTime)...
Chronos::date('2022-05-05 10:10:10')...
Chronos::date(1664524279)...

new Chronos(new DateTime)
```

Or just get the current datetime.

```
Chronos::date()...
```

DateTime Options
----------------

[](#datetime-options)

You can specify each option fluently after setting the initial date.

```
Chronos::date($date)
  ->setDateTimeFormat("Y-m-d H:i:s")
  ->setDateFormat("Y-m-d")
  ->setTimeFormat("H:i:s")
  ->setTimezone("UTC")
```

Retrieving the datetime as a string
-----------------------------------

[](#retrieving-the-datetime-as-a-string)

You have multiple methods to retrieve the datetime as a string.

```
 Chronos::date($date)...
     ->getDateObject()
     ->stamp()
     ->getDateTime()
     ->getDate()
     ->getTime()
     ->getHour()
     ->getMinute()
     ->getSeconds()
     ->getDayName()
     ->getDayShortName()
     ->getDayNumber()
     ->getWeekNumber()
     ->getMonthName()
     ->getShortMonthName()
     ->getMonthNumber()
     ->getYear()
```

Manipulating datetime
---------------------

[](#manipulating-datetime)

### Initial methods

[](#initial-methods)

You have several methods to manipulate the initial time before retrieving it as a string.

```
 Chronos::date($date)->addDays()->getDateTime();
 Chronos::date($date)->addMinutes()->getDateTime();
 Chronos::date($date)->addSeconds()->getDateTime();
 Chronos::date($date)->subDays()->getDateTime();
 Chronos::date($date)->subMinutes()->getDateTime();
 Chronos::date($date)->subSeconds()->getDateTime();
```

### Chaining methods

[](#chaining-methods)

You can also chain the methods fluently.

```
 Chronos::date($date)->addDays(40)->addMinutes(1)->subSeconds(20)->getDateTime();
```

Traveling in time
-----------------

[](#traveling-in-time)

### Setting the new datetime

[](#setting-the-new-datetime)

You can set another datetime as a DateTime object or a valid date string or a timestamp to work with intervals.

```
Chronos::date()->travel(new DateTime)...
Chronos::date()->travel('2022-05-05 10:10:10')...
Chronos::date()->travel(1664524279)...
```

### Retrieving the difference

[](#retrieving-the-difference)

You have multiple methods to retrieve the difference as a string.

```
Chronos::date()->travel('2022-05-05 10:10:10')
    ->daysPassed() // This will return 0 if travel date is in the future.
    ->differenceInDays() // This will return negative days if travel is in the past.
    ->hoursPassed()
    ->differenceInHours()
    ->minutesPassed()
    ->differenceInMinutes()
    ->secondsPassed()
    ->differenceInSeconds()
```

You can also do a fast check to see weather we are in the past or future.

```
Chronos::date()->travel('2022-05-05 10:10:10')
   ->isInFuture()
   ->isInPast()
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Unknown

Total

1

Last Release

1345d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/72206204?v=4)[Petrik Gábor](/maintainers/Twipsi)[@Twipsi](https://github.com/Twipsi)

---

Top Contributors

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

---

Tags

timedateinterval

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/twipsi-chronos/health.svg)

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

###  Alternatives

[league/period

Time range API for PHP

7335.8M24](/packages/league-period)[brick/date-time

Date and time library

3663.8M105](/packages/brick-date-time)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6339.5M56](/packages/knplabs-knp-time-bundle)[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)[kartik-v/yii2-date-range

An advanced Yii 2 date range picker input for based on bootstrap-daterangepicker plugin.

924.6M42](/packages/kartik-v-yii2-date-range)

PHPackages © 2026

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