PHPackages                             henzeb/datetime - 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. henzeb/datetime

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

henzeb/datetime
===============

Simple testable DateTime instances

v1.1.0(2y ago)0331AGPL-3.0-onlyPHPPHP ^7.4|^8.0

Since Apr 25Pushed 2y ago2 watchersCompare

[ Source](https://github.com/henzeb/datetime)[ Packagist](https://packagist.org/packages/henzeb/datetime)[ Docs](https://github.com/henzeb/laravel-console)[ RSS](/packages/henzeb-datetime/feed)WikiDiscussions master Synced today

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

DateTime
========

[](#datetime)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b58361a583f18a7fc5d11ee52725c8299f9b9b3920d610976f0e853a19d607e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656e7a65622f6461746574696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/datetime)[![Total Downloads](https://camo.githubusercontent.com/d0f5380815c623203d9aeefb97f1d644863ef7fc17e3d3b6681eb376ec946d85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656e7a65622f6461746574696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/datetime)

This package is useful when creating a library or functionality that requires speed over functionality, but still being useful for testing needs.

Don't get me wrong, Carbon is a great package when it comes to modifying DateTime objects, I use it all the time. But it comes with a price. When you need a lot of its powers, you will see the overhead grow. Faster than using vanilla `DateTime`.

If you don't want your library to be the bottleneck of someone else their code, but still want to be able to test with the ability of changing dates or times, you can use this package.

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

[](#installation)

Just install with the following command.

```
composer require henzeb/datetime
```

Usage
-----

[](#usage)

```
use Henzeb\DateTime\DateTime;
DateTime::now();
DateTime::now(new DateTimeZone(...));
DateTime::new('2022-04-25');
```

### Immutable DateTime

[](#immutable-datetime)

```
use Henzeb\DateTime\DateTimeImmutable;
DateTimeImmutable::now();
DateTimeImmutable::now(new DateTimeZone(...));
DateTimeImmutable::new('2022-04-25');
```

Note: there is no convenient methods or functionality other than `new` and `now`, It's just vanilla `DateTime`or `DateTimeImmutable` with `timetravel` capabilities.

### Unit testing

[](#unit-testing)

Just like Carbon, this library has a static `setTestNow` method. You can pass a string or a DateTime object. When passing `null`, new DateTime objects will use current date/time again.

```
use Henzeb\DateTime\DateTime;
DateTime::setTestNow('now'); // freezes time
DateTime::setTestNow('1999-01-01');
DateTime::setTestNow(new DateTime('1999-01-01'));
```

Testing
-------

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Henze Berkheij](https://github.com/henzeb)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

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

Every ~657 days

Total

2

Last Release

872d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15928532?v=4)[henzeb](/maintainers/henzeb)[@henzeb](https://github.com/henzeb)

---

Top Contributors

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

---

Tags

datetimetimedatecarbonunittesthenzeb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/henzeb-datetime/health.svg)

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

###  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)[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/php-date-formatter

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

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

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

14484.2k](/packages/dater-dater)

PHPackages © 2026

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