PHPackages                             rxante/dateimmutable - 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. rxante/dateimmutable

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

rxante/dateimmutable
====================

1.0.0(1y ago)01.1k↓34.6%Apache-2.0PHPPHP ^8.2CI passing

Since Jan 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/RxAnte/PHPDateImmutable)[ Packagist](https://packagist.org/packages/rxante/dateimmutable)[ RSS](/packages/rxante-dateimmutable/feed)WikiDiscussions main Synced 1mo ago

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

PHPDateImmutable
================

[](#phpdateimmutable)

This is an implementation of a `DateImmutable` class that deals only with dates and not with time. PHP has, of course, built-in, `DateTime` and `DateTimeImmutable` classes. We have found that we frequently want a class that deals only with the date.

This `DateImmutable` class implements all the same methods that PHP's `DateTimeImmutable` does, and in the same way, except where the method wouldn't make sense for a class that does not deal with time.

Methods
-------

[](#methods)

### The Constructor

[](#the-constructor)

`DateImmutable`'s constructor works exactly the same way as `DateTimeImmutable`'s does, except that it does not accept a `DateTimeZone` as a second argument because timezones do not matter when you're not dealing with time.

```
$today = new \RxAnte\DateImmutable('now');
$specificDate = new \RxAnte\DateImmutable('2008-04-29');
```

### `diff` (instance method)

[](#diff-instance-method)

Returns the difference between its own instance, and another instance of either `DateImmutable` or the `DateTimeInterface`

```
$dateTime = new \DateTimeImmutable('2006-03-20 02:03:04');

$date = new \RxAnte\DateImmutable('2001-02-19');

$diff = $date->diff($dateTime);

// OR

$anotherDate = $date = new \RxAnte\DateImmutable('2001-02-12');

$diff2 = $date->diff($anotherDate);
```

### `format` (instance method)

[](#format-instance-method)

Takes all the same options that PHP's `DateTimeInterface` does:

If any time formatting tokens are used, 0s will always be returned since there is no time on the `DateImmutable` class.

```
$date = new \RxAnte\DateImmutable('2008-04-29');

$format = $date->format('Y-m-d h:i:s'); // outputs 2008-04-29 12:00:00
```

### `getTimestamp` (instance method)

[](#gettimestamp-instance-method)

Gets the unix timestamp of UTC midnight for the given date.

```
$date = new \RxAnte\DateImmutable('2008-04-29 08:22:23')

$timestamp = $date->getTimestamp(); // outputs 1209427200
```

### `add` (instance method)

[](#add-instance-method)

Adds an amount of days, months, and years to the existing instance's value, and returns a new instance with the new values.

Any hours, minutes, or seconds on the `DateInterval` argument input will be ignored.

```
$date = (new \RxAnte\DateImmutable('2008-04-29 08:22:23'))
    ->add(\DateInterval::createFromDateString('1 week'));

$formatted = $date->format('Y-m-d'); // outputs 2008-05-06
```

### `createFromFormat` (static method)

[](#createfromformat-static-method)

Returns new DateImmutable object formatted according to the specified format.

Takes all the same options that PHP's `DateTimeImmutable` does:

```
$date = \RxAnte\DateImmutable::createFromFormat(
    'm/d/y',
    '01/27/82',
);
```

### `modify` (instance method)

[](#modify-instance-method)

Creates a new instance of `DateImmutable` modified by the input.

Takes all the same options that PHP's `DateTime` classes do:

```
$date = new \RxAnte\DateImmutable('1982-01-27');

$modified = $date->modify('+1 day');
```

### `setDate` (instance method)

[](#setdate-instance-method)

Sets the date to the input year/month/day and returns a new instance of the class with that value.

```
$date = new \RxAnte\DateImmutable('1982-01-27');

$newDate = $date->setDate(2002, 2, 3);
```

### `setISODate` (instance method)

[](#setisodate-instance-method)

Sets the date to the input year/week/dayOfWeek and returns a new instance of the class with that value.

```
$date = new \RxAnte\DateImmutable('1982-01-27');

$newDate = $date->setISODate(2005, 30, 2);
```

### `sub` (instance method)

[](#sub-instance-method)

Subtracts an amount of days, months, and years from the existing instance's value, and returns a new instance with the new values.

Any hours, minutes, or seconds on the `DateInterval` argument input will be ignored.

```
$date = (new \RxAnte\DateImmutable('2008-04-29'))
    ->sub(\DateInterval::createFromDateString('1 week'));

$formatted = $date->format('Y-m-d'); // outputs 2008-04-22
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance41

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

494d ago

### Community

Maintainers

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

---

Top Contributors

[![tjdraper](https://avatars.githubusercontent.com/u/3803475?v=4)](https://github.com/tjdraper "tjdraper (19 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rxante-dateimmutable/health.svg)

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

PHPackages © 2026

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