PHPackages                             baumrock/humandates - 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. baumrock/humandates

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

baumrock/humandates
===================

Format date ranges in a human-readable format with automatic pattern selection and localization support.

v1.1.1(2y ago)15371MITPHPPHP &gt;=8.0

Since Jun 13Pushed 2y ago2 watchersCompare

[ Source](https://github.com/baumrock/HumanDates)[ Packagist](https://packagist.org/packages/baumrock/humandates)[ RSS](/packages/baumrock-humandates/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

HumanDates
==========

[](#humandates)

HumanDates is a PHP library that provides convenient methods for formatting dates as human-readable strings and generating human-friendly date ranges. It uses the `IntlDateFormatter` class to ensure accurate localization and formatting based on the specified locale.

```
 1.1.2023 - 3.1.2023
 1. - 3.1.2023
```

[![image](https://private-user-images.githubusercontent.com/8488586/249723029-59a2a9fb-a925-4c79-8d99-f199583a3bcc.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzM5MDc4OTYsIm5iZiI6MTc3MzkwNzU5NiwicGF0aCI6Ii84NDg4NTg2LzI0OTcyMzAyOS01OWEyYTlmYi1hOTI1LTRjNzktOGQ5OS1mMTk5NTgzYTNiY2MucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDMxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAzMTlUMDgwNjM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Mjc2NmFkZTZmMWVlNDE3NGNkMmQ5MzM1NThhOWI3Y2ZmNjQxMzQxMjQ3NTJlMDczMTVlNmIzZDlhNzgzYjcxOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.l31G8OhAA-JEpFMnxzM8qVV5vGwZJeddeOEwDDobbgc)](https://private-user-images.githubusercontent.com/8488586/249723029-59a2a9fb-a925-4c79-8d99-f199583a3bcc.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzM5MDc4OTYsIm5iZiI6MTc3MzkwNzU5NiwicGF0aCI6Ii84NDg4NTg2LzI0OTcyMzAyOS01OWEyYTlmYi1hOTI1LTRjNzktOGQ5OS1mMTk5NTgzYTNiY2MucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDMxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAzMTlUMDgwNjM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Mjc2NmFkZTZmMWVlNDE3NGNkMmQ5MzM1NThhOWI3Y2ZmNjQxMzQxMjQ3NTJlMDczMTVlNmIzZDlhNzgzYjcxOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.l31G8OhAA-JEpFMnxzM8qVV5vGwZJeddeOEwDDobbgc)Usage
-----

[](#usage)

To get started, include the HumanDates library and create a new instance:

```
// manual download
require_once "/path/to/HumanDates.php";

// using composer
// composer require baumrock/humandates
require_once "/path/to/composer/autoload.php";

// create HumanDates instance
$dates = new HumanDates();
echo $dates->format("2023-01-01");              // 1. Jan 2023
echo $dates->range("2023-01-01", "2023-01-03"); // 1. - 3. Jan 2023
```

Why Use HumanDates?
-------------------

[](#why-use-humandates)

HumanDates provides several benefits and reasons to consider using it in your PHP projects:

1. Simplified Date Formatting

    HumanDates simplifies the process of formatting dates in PHP. It offers a straightforward and intuitive API for formatting both single dates and date ranges, eliminating the need for complex and error-prone manual formatting.
2. Localization Support

    HumanDates leverages the `IntlDateFormatter` class, ensuring accurate localization of date formats based on the specified locale. This allows you to generate date strings that are culturally appropriate and easily understood by users from different regions.
3. Customizable Date Range Formats

    With HumanDates, you have the flexibility to define custom format patterns for date ranges. You can easily tailor the output to match your specific requirements, such as including or excluding certain date components, adjusting separators, or changing the order of elements.
4. Replacement for Deprecated `strftime()`

    As of PHP 8, the `strftime()` function is deprecated and will be removed in PHP 9. HumanDates can serve as a replacement for `strftime()`, providing a modern and reliable alternative for formatting dates in PHP.
5. MIT License

    HumanDates is released under the permissive MIT License, allowing you to freely use, modify, and distribute the library in your projects, both personal and commercial.

By using HumanDates, you can enhance the user experience by presenting dates in a human-readable format, improve code maintainability, and ensure consistent and accurate date formatting across your application.

Give HumanDates a try and simplify your date formatting needs with ease!

Formatting a Single Date
------------------------

[](#formatting-a-single-date)

You can format a single date using the `format()` method, which can serve as a replacement for the `strftime()` function which is deprecated in PHP8 and will be removed in PHP9:

```
echo $dates->format("2023-01-01", "d.M.y"); // Output: 1.1.2023
```

The `format()` method accepts a date string or timestamp as the first parameter and an optional format pattern as the second parameter. The format pattern follows the syntax defined by the `IntlDateFormatter` class: [See here for a list of all available letters](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table).

Formatting a Date Range
-----------------------

[](#formatting-a-date-range)

HumanDates provides a convenient way to format date ranges as well. Use the `range()` method by passing the start and end dates:

```
// example using locale de_DE
echo $dates->range("2023-01-01", "2023-02-03"); // Output: 1. Jan. - 3. Feb. 2023
echo $dates->range("2023-01-01", "2023-01-03"); // Output: 1. - 3. Jan. 2023
```

By default, the `range()` method uses predefined patterns to format the date range. However, you can also specify custom patterns by providing an array of patterns as the third parameter:

```
// example using locale de_DE
echo $dates->range("2023-01-01", "2023-01-03", [
	'default'   => ['d. MMMM y', ' bis ', 'd. MMMM y'], // 1. Januar 2023 bis 3. Februar 2024
	'sameYear'  => ['d. MMMM',   ' bis ', 'd. MMMM y'], // 1. Januar bis 3. Februar 2023
	'sameMonth' => ['d.',        ' bis ', 'd. MMMM y'], // 1. bis 3. Januar 2023
	'sameDay'   => ['d. MMMM y'],                       // 1. Januar 2023
]);
```

Note that this will set the patterns for this single request only! If you want to modify the globally used patterns you can do this:

```
echo $dates->setPatterns(...)->range(...);
```

Setting Locales
---------------

[](#setting-locales)

You can set the locale for date formatting either globally for the current `HumanDates` instance or on a per-format basis.

To set the locale globally, pass the desired locale as a parameter when creating a new `HumanDates` instance:

```
$dates = new HumanDates("de_AT");
echo $dates->format($timestamp, "d. MMMM y"); // Output: 1. Jänner 2023
```

To set the locale for a specific `format()` call, include the `locale` parameter:

```
echo $dates->format(
  $timestamp,
  format: "d. MMMM y",
  locale: "de_DE",
); // Output: 1. Januar 2023
```

Setting Defaults
----------------

[](#setting-defaults)

You can set default formatting options for your `HumanDates` instance by specifying the locale and format pattern during initialization:

```
$dates = new HumanDates("de_AT", "dd.MM.y");
echo $dates->format("2023-1-1"); // Output: 01.01.2023
echo $dates->format("2023-1-1", "d. MMMM y"); // Output: 1. Jänner 2023
```

Star the Repository
-------------------

[](#star-the-repository)

If you find HumanDates useful or interesting, please star the repository on GitHub. By starring the repository, you show your appreciation and support for the project. It also helps us understand the level of community interest and motivates us to further improve the library. ⭐

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.8% 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 ~33 days

Recently: every ~49 days

Total

7

Last Release

870d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ee153aec1408fd84b61e2921c97a05bf8f6a0da4caa610665acd02f54bbbf17?d=identicon)[baumrock](/maintainers/baumrock)

---

Top Contributors

[![BernhardBaumrock](https://avatars.githubusercontent.com/u/8488586?v=4)](https://github.com/BernhardBaumrock "BernhardBaumrock (15 commits)")[![romaincazier](https://avatars.githubusercontent.com/u/6616448?v=4)](https://github.com/romaincazier "romaincazier (1 commits)")

---

Tags

dateshuman-readablephp

### Embed Badge

![Health badge](/badges/baumrock-humandates/health.svg)

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

###  Alternatives

[jcbrand/converse.js

Browser based XMPP instant messaging client

3.2k156.6k](/packages/jcbrand-conversejs)[pastuhov/yii2-yml-catalog

YML (Yandex Market Language) generator.

2116.7k](/packages/pastuhov-yii2-yml-catalog)[flagbit/table-attribute-bundle

The Flagbit Table Attribute Bundle for Akeneo PIM gives you the possibility to enrich your product with multi-dimensional data presentation in the form of tables, allowing you maximum flexibility within the PIM.

2310.4k](/packages/flagbit-table-attribute-bundle)

PHPackages © 2026

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