PHPackages                             deviantintegral/null-date-time - 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. deviantintegral/null-date-time

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

deviantintegral/null-date-time
==============================

Interfaces and classes supporting empty or null DateTime objects

v1.1.1(4mo ago)019.7k↑128.6%[1 PRs](https://github.com/deviantintegral/null-date-time/pulls)1MITPHPPHP ^8.2CI passing

Since Aug 22Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/deviantintegral/null-date-time)[ Packagist](https://packagist.org/packages/deviantintegral/null-date-time)[ RSS](/packages/deviantintegral-null-date-time/feed)WikiDiscussions main Synced 1mo ago

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

Null Date Time for PHP
======================

[](#null-date-time-for-php)

[![CI](https://github.com/deviantintegral/null-date-time/actions/workflows/ci.yml/badge.svg)](https://github.com/deviantintegral/null-date-time/actions/workflows/ci.yml)[![Packagist Downloads](https://camo.githubusercontent.com/ac62c894d38abeddebc1858b54a493385d985e03d628c5f291a7e1af9b614b1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657669616e74696e74656772616c2f6e756c6c2d646174652d74696d65)](https://packagist.org/packages/deviantintegral/null-date-time)

`composer require deviantintegral/null-date-time`

This package provides classes that decorate \\DateTime so that it is always formattable as a string, even if the time is empty or null.

PHP's \\DateTime object does not have any way to represent an "empty" date. While there is a \\DateTimeInterface class, it's documentation explicitly says it is not for implementation but type hinting only.

We don't want calling code to have to check for null returns on every get call. DateTimeFormatInterface requires that format() return an empty string if the underlying date is not set.

When constructing a DateTime object, a common pattern would be:

```
