PHPackages                             stellarwp/dates - 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. stellarwp/dates

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

stellarwp/dates
===============

Date utilities and classes.

1.1.3(1y ago)918.2k↓18.6%MITPHPCI failing

Since Mar 30Pushed 10mo ago5 watchersCompare

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

READMEChangelog (7)Dependencies (14)Versions (11)Used By (0)

StellarWP Dates
===============

[](#stellarwp-dates)

[![Tests](https://github.com/stellarwp/dates/workflows/Tests/badge.svg)](https://github.com/stellarwp/dates/actions?query=branch%3Amain) [![Static Analysis](https://github.com/stellarwp/dates/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/stellarwp/dates/actions/workflows/static-analysis.yml)

A collection of date utilities authored by the development team at [StellarWP](https://stellarwp.com) and provided free for the WordPress community.

*This work is forked from the battle-tested date handling done at [The Events Calendar](https://theeventscalendar.com)!*

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

[](#installation)

It's recommended that you install Dates as a project dependency via [Composer](https://getcomposer.org/):

```
composer require stellarwp/dates
```

> We *actually* recommend that this library gets included in your project using [Strauss](https://github.com/BrianHenryIE/strauss).
>
> Luckily, adding Strauss to your `composer.json` is only slightly more complicated than adding a typical dependency, so checkout our [strauss docs](https://github.com/stellarwp/global-docs/blob/main/docs/strauss-setup.md).

Documentation
-------------

[](#documentation)

- [How dates are built](#how-dates-are-built)
- [Constants](#constants)
- [Dates](/docs/classes/StellarWP/Dates/Dates.md)
    - [build\_date\_object](/docs/classes/StellarWP/Dates/Dates.md#build_date_object) - alias for `mutable()`
    - [build\_localized\_months](/docs/classes/StellarWP/Dates/Dates.md#build_localized_months)
    - [build\_localized\_weekdays](/docs/classes/StellarWP/Dates/Dates.md#build_localized_weekdays)
    - [catch\_and\_throw](/docs/classes/StellarWP/Dates/Dates.md#catch_and_throw)
    - [clear\_cache](/docs/classes/StellarWP/Dates/Dates.md#clear_cache)
    - [date](/docs/classes/StellarWP/Dates/Dates.md#date) - alias for `date_only()`
    - [date\_diff](/docs/classes/StellarWP/Dates/Dates.md#date_diff) - alias for `diff()`
    - [date\_only](/docs/classes/StellarWP/Dates/Dates.md#date_only)
    - [datetime\_from\_format](/docs/classes/StellarWP/Dates/Dates.md#datetime_from_format)
    - [diff](/docs/classes/StellarWP/Dates/Dates.md#diff)
    - [first\_day\_in\_month](/docs/classes/StellarWP/Dates/Dates.md#first_day_in_month)
    - [get](/docs/classes/StellarWP/Dates/Dates.md#get) - calls `immutable()` (default) or `mutable()`
    - [get\_cache](/docs/classes/StellarWP/Dates/Dates.md#get_cache)
    - [get\_first\_day\_of\_week\_in\_month](/docs/classes/StellarWP/Dates/Dates.md#get_first_day_of_week_in_month)
    - [get\_last\_day\_of\_month](/docs/classes/StellarWP/Dates/Dates.md#get_last_day_of_month)
    - [get\_last\_day\_of\_week\_in\_month](/docs/classes/StellarWP/Dates/Dates.md#get_last_day_of_week_in_month)
    - [get\_localized\_months\_full](/docs/classes/StellarWP/Dates/Dates.md#get_localized_months_full)
    - [get\_localized\_months\_short](/docs/classes/StellarWP/Dates/Dates.md#get_localized_months_short)
    - [get\_localized\_weekdays\_full](/docs/classes/StellarWP/Dates/Dates.md#get_localized_weekdays_full)
    - [get\_localized\_weekdays\_initial](/docs/classes/StellarWP/Dates/Dates.md#get_localized_weekdays_initial)
    - [get\_localized\_weekdays\_short](/docs/classes/StellarWP/Dates/Dates.md#get_localized_weekdays_short)
    - [get\_modifier\_from\_offset](/docs/classes/StellarWP/Dates/Dates.md#get_modifier_from_offset)
    - [get\_week\_start\_end](/docs/classes/StellarWP/Dates/Dates.md#get_week_start_end)
    - [get\_weekday\_timestamp](/docs/classes/StellarWP/Dates/Dates.md#get_weekday_timestamp)
    - [has\_cache](/docs/classes/StellarWP/Dates/Dates.md#has_cache)
    - [hour](/docs/classes/StellarWP/Dates/Dates.md#hour) - alias for `hour_only()`
    - [hour\_only](/docs/classes/StellarWP/Dates/Dates.md#hour_only)
    - [immutable](/docs/classes/StellarWP/Dates/Dates.md#immutable)
    - [interval](/docs/classes/StellarWP/Dates/Dates.md#interval)
    - [is\_after](/docs/classes/StellarWP/Dates/Dates.md#is_after)
    - [is\_before](/docs/classes/StellarWP/Dates/Dates.md#is_before)
    - [is\_between](/docs/classes/StellarWP/Dates/Dates.md#is_date_between)
    - [is\_now](/docs/classes/StellarWP/Dates/Dates.md#is_now) - calls `is_between()` with a different parameter order, where the date to look for is last and optional.
    - [is\_timestamp](/docs/classes/StellarWP/Dates/Dates.md#is_timestamp)
    - [is\_valid](/docs/classes/StellarWP/Dates/Dates.md#is_valid)
    - [is\_valid\_date](/docs/classes/StellarWP/Dates/Dates.md#is_valid_date) - alias for `is_valid()`
    - [is\_weekday](/docs/classes/StellarWP/Dates/Dates.md#is_weekday)
    - [is\_weekend](/docs/classes/StellarWP/Dates/Dates.md#is_weekend)
    - [last\_day\_in\_month](/docs/classes/StellarWP/Dates/Dates.md#last_day_in_month)
    - [meridian](/docs/classes/StellarWP/Dates/Dates.md#meridian) - alias for `meridian_only()`
    - [meridian\_only](/docs/classes/StellarWP/Dates/Dates.md#meridian_only)
    - [minutes](/docs/classes/StellarWP/Dates/Dates.md#minutes)
    - [minutes\_only](/docs/classes/StellarWP/Dates/Dates.md#minutes_only)
    - [mutable](/docs/classes/StellarWP/Dates/Dates.md#mutable)
    - [number\_to\_ordinal](/docs/classes/StellarWP/Dates/Dates.md#number_to_ordinal)
    - [range\_coincides](/docs/classes/StellarWP/Dates/Dates.md#range_coincides) - alias for `range_overlaps()`
    - [range\_overlaps](/docs/classes/StellarWP/Dates/Dates.md#range_overlaps)
    - [reformat](/docs/classes/StellarWP/Dates/Dates.md#reformat)
    - [round\_nearest\_half\_hour](/docs/classes/StellarWP/Dates/Dates.md#round_nearest_half_hour)
    - [seconds](/docs/classes/StellarWP/Dates/Dates.md#seconds) - alias for `seconds_only()`
    - [seconds\_only](/docs/classes/StellarWP/Dates/Dates.md#seconds_only)
    - [set\_cache](/docs/classes/StellarWP/Dates/Dates.md#set_cache)
    - [sort](/docs/classes/StellarWP/Dates/Dates.md#sort)
    - [time\_between](/docs/classes/StellarWP/Dates/Dates.md#time_between)
    - [time](/docs/classes/StellarWP/Dates/Dates.md#time) - alias for `time_only()`
    - [time\_only](/docs/classes/StellarWP/Dates/Dates.md#time_only)
    - [unescape\_date\_format](/docs/classes/StellarWP/Dates/Dates.md#unescape_date_format)
    - [week\_ends\_on](/docs/classes/StellarWP/Dates/Dates.md#week_ends_on)
    - [wp\_strtotime](/docs/classes/StellarWP/Dates/Dates.md#wp_strtotime)
    - [wp\_locale\_month](/docs/classes/StellarWP/Dates/Dates.md#wp_locale_month)
    - [wp\_locale\_weekday](/docs/classes/StellarWP/Dates/Dates.md#wp_locale_weekday)
- [Date\_I18n](/docs/classes/StellarWP/Dates/Date_I18n.md)
    - [createFromImmutable](/docs/classes/StellarWP/Dates/Date_I18n.md#createfromimmutable)
    - [format\_i18n](/docs/classes/StellarWP/Dates/Date_I18n.md#format_i18n)
- [Date\_I18n\_Immutable](/docs/classes/StellarWP/Dates/Date_I18n_Immutable.md)
    - [createFromMutable](/docs/classes/StellarWP/Dates/Date_I18n_Immutable.md#createfrommutable)
    - [format\_i18n](/docs/classes/StellarWP/Dates/Date_I18n_Immutable.md#format_i18n)
- [Timezones](/docs/classes/StellarWP/Dates/Timezones.md)
    - [abbr](/docs/classes/StellarWP/Dates/Timezones.md#abbr)
    - [apply\_offset](/docs/classes/StellarWP/Dates/Timezones.md#apply_offset)
    - [build\_timezone\_object](/docs/classes/StellarWP/Dates/Timezones.md#build_timezone_object)
    - [clear\_site\_timezone\_abbr](/docs/classes/StellarWP/Dates/Timezones.md#clear_site_timezone_abbr)
    - [convert\_date\_from\_timezone\_to\_timezone](/docs/classes/StellarWP/Dates/Timezones.md#convert_date_from_timezone_to_timezone)
    - [generate\_timezone\_string\_from\_utc\_offset](/docs/classes/StellarWP/Dates/Timezones.md#generate_timezone_string_from_utc_offset)
    - [get\_system\_timezone](/docs/classes/StellarWP/Dates/Timezones.md#get_system_timezone)
    - [get\_timezone](/docs/classes/StellarWP/Dates/Timezones.md#get_timezone)
    - [get\_valid\_timezone](/docs/classes/StellarWP/Dates/Timezones.md#get_valid_timezone)
    - [invalided\_caches](/docs/classes/StellarWP/Dates/Timezones.md#invalided_caches)
    - [is\_mode](/docs/classes/StellarWP/Dates/Timezones.md#is_mode)
    - [is\_utc\_offest](/docs/classes/StellarWP/Dates/Timezones.md#is_utc_offest)
    - [is\_valid\_timezone](/docs/classes/StellarWP/Dates/Timezones.md#is_valid_timezone)
    - [localize\_date](/docs/classes/StellarWP/Dates/Timezones.md#localize_date)
    - [maybe\_get\_tz\_name](/docs/classes/StellarWP/Dates/Timezones.md#maybe_get_tz_name)
    - [timezone\_from\_utc\_offset](/docs/classes/StellarWP/Dates/Timezones.md#timezone_from_utc_offset)
    - [to\_tz](/docs/classes/StellarWP/Dates/Timezones.md#to_tz)
    - [to\_utc](/docs/classes/StellarWP/Dates/Timezones.md#to_utc)
    - [wp\_timezone\_abbr](/docs/classes/StellarWP/Dates/Timezones.md#wp_timezone_abbr)
    - [wp\_timezone\_string](/docs/classes/StellarWP/Dates/Timezones.md#wp_timezone_string)

### How dates are built

[](#how-dates-are-built)

The `Dates::get()` method accepts a number of parameters (a date, a timezone, a fallback date, and an immutable flag). However, you can get the current datetime with a simple call to `Dates::get()` like so:

```
use StellarWP\Dates\Dates;

$date = Dates::get();
```

Whether you are using that simple approach or something more complex, here's what is happening under the hood:

 ```
flowchart TD
  is_immutable{"Immutable?"} -- yes --> yes_immutable["All dates returned will be Date_I18n_Immutable"]
  is_immutable -- no --> no_immutable["All dates returned will be Date_I18n"]
  yes_immutable --> is_timezone_set{"Is the timezone set?"}
  no_immutable --> is_timezone_set
  is_timezone_set -- yes --> create_timezone["Create a DateTimeZone object from $timezone"]
  is_timezone_set -- no --> is_wp_timezone_set{"Is there a WP timezone string?"}
  is_wp_timezone_set -- yes --> use_wp_timezone["$timezone = WP timezone string"]
  is_wp_timezone_set -- no --> is_timezone_valid{"Is $timezone valid?"}
  is_timezone_valid -- yes --> create_timezone
  is_timezone_valid -- no --> use_utc["$timezone = UTC"]
  use_wp_timezone --> create_timezone
  use_utc --> create_timezone
  create_timezone --> create_date["$date = date object using $datetime with $timezone"]
  create_date --> is_error{Error when creating date object?}
  is_error -- yes --> should_fallback{"Is a fallback date desired?"}
  should_fallback -- no --> no_fallback((Return false))
  should_fallback -- yes --> yes_fallaback["$date = 'now' date object with $timezone"]
  is_error -- no --> final
  yes_fallaback --> final((Return $date))
```

      Loading ### Constants

[](#constants)

ConstantFormatDescription`DATEONLYFORMAT``F j, Y`The date format used for date-only strings.`TIMEFORMAT``g:i A`The time format used for time-only strings.`HOURFORMAT``g`The hour format used for hour-only strings.`MINUTEFORMAT``i`The minute format used for minute-only strings.`MERIDIANFORMAT``A`The meridian format used for meridian-only strings.`DBDATEFORMAT``Y-m-d`The date format used for date-only strings in the database.`DBDATETIMEFORMAT``Y-m-d H:i:s`The date format used for date-time strings in the database.`DBTZDATETIMEFORMAT``Y-m-d H:i:s O`The date format used for date-time strings in the database with timezone.`DBTIMEFORMAT``H:i:s`The date format used for time-only strings in the database.`DBYEARMONTHTIMEFORMAT``Y-m`The date format used for year-month strings in the database.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance45

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity51

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 ~66 days

Recently: every ~133 days

Total

9

Last Release

614d ago

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/70a2847a265444714b48c64eceb3ca742baa3a56757ce65b18bd7bbbbf910312?d=identicon)[dpanta94](/maintainers/dpanta94)

![](https://www.gravatar.com/avatar/97fd764aa710e8d8263a7e3b3fececdfd736b8aad8055227bf592ddf50ad15ba?d=identicon)[stellarwp](/maintainers/stellarwp)

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

---

Top Contributors

[![borkweb](https://avatars.githubusercontent.com/u/430385?v=4)](https://github.com/borkweb "borkweb (26 commits)")

---

Tags

wordpress-librarywordpress-php-library

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stellarwp-dates/health.svg)

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

###  Alternatives

[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[malukenho/mcbumpface

Bumping into packages

116714.7k24](/packages/malukenho-mcbumpface)[inovector/mixpostapp

Standalone application with the Laravel Package of Mixpost Lite pre-installed and configured

1232.9k](/packages/inovector-mixpostapp)[joserick/laravel-livewire-discover

Discover and autoload multiples components of livewire by convention (componentNamespace)

2736.6k2](/packages/joserick-laravel-livewire-discover)[neysi/directprint

Easy and direct file print from PHP

218.3k](/packages/neysi-directprint)

PHPackages © 2026

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