PHPackages                             studioespresso/craft-date-range - 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. studioespresso/craft-date-range

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

studioespresso/craft-date-range
===============================

Date range field

5.1.0(2mo ago)1222.6k—0%8[6 issues](https://github.com/studioespresso/craft-date-range/issues)[2 PRs](https://github.com/studioespresso/craft-date-range/pulls)1MITPHPPHP ^8.2CI passing

Since Oct 24Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/studioespresso/craft-date-range)[ Packagist](https://packagist.org/packages/studioespresso/craft-date-range)[ GitHub Sponsors](https://github.com/sponsors/janhenckens)[ RSS](/packages/studioespresso-craft-date-range/feed)WikiDiscussions develop-v5 Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (31)Used By (1)

Date Range field for Craft CMS
==============================

[](#date-range-field-for-craft-cms)

What is says on the tin 🙂. This field gives you a start and end date in 1 field.

[![](https://camo.githubusercontent.com/48170917f8ca75a2777f9cbe6f170b2a6bb16a11fcaa78566a29f0898585b63b/68747470733a2f2f7777772e73747564696f657370726573736f2e636f2f6173736574732f646174652d72616e67652d6769746875622d62616e6e65722e706e67)](https://camo.githubusercontent.com/48170917f8ca75a2777f9cbe6f170b2a6bb16a11fcaa78566a29f0898585b63b/68747470733a2f2f7777772e73747564696f657370726573736f2e636f2f6173736574732f646174652d72616e67652d6769746875622d62616e6e65722e706e67)

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3, 4 or 5.

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

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project
     composer require studioespresso/craft-date-range
     ./craft install/plugin date-range

    ```

Settings
--------

[](#settings)

The following options can be set on the field:

- Show a start time field
- Show an end time field
- End date should be after or later thand the start date

When the field is set to required, both start &amp; end date (and if enabled time) will be required.

Default time values
-------------------

[](#default-time-values)

Since a PHP `DateTime` object also has a time value, wether you entered on or not (or wether you have to option enabled to show the fields or not), the plugin tries to be smart in which time values get saved.

When you enable either or both time fields, that value will off course be safed. For fields that don't have time options set, `00:00:00` will get saved.

Upgrading to Craft 5
--------------------

[](#upgrading-to-craft-5)

With Craft 5 comes multi-instance support (fields can be used multiple times in the same layout) and this adds a bit of complexity for the Date Range plugin. In the query behaviour, you'll need to add the handle of the entry type you're trying to query as a second argument.

```
// Craft 4
{% set events = craft.entries.section('events').isFuture('dateRangeFieldHandle')  %}

// Craft 5
{% set events = craft.entries.section('events').isFuture('dateRangeFieldHandle', 'entryTypeHandle')  %}
```

Templating
----------

[](#templating)

### Element queries

[](#element-queries)

⚠️ Using date range fields in your entry queries is possible but requires the site to be running **MySQL 5.7 or later** or **PostgreSQL 9.3 or later**.

Example:

```
{% set events = craft.entries.section('events').isFuture('dateRangeFieldHandle', 'entryTypeHandle')  %}
```

The plugin includes the following query behaviors:

- `isFuture()` - entries where the start date is in the future
- `isPast()` - entries where the end date is in the past
- `isNotPast()` - entries where the end date is in the future
- `isOnGoing()` - entries where the start date is in the past and the end date is in the future
- `startsAfterDate()` - entries where the start date is after the given date
- `endsBeforeDate()` - entries where the end date is before the given date
- `isDuringDate()` - entries where the date range overlaps with the given date or date range
- `isNotDuringDate()` - entries where the date range does not overlap with the given date or date range

The second argument passed should be the handle of the entry type you want to query.

You can optionally pass `true` as a third argument to `isFuture`, `isPast`, `isNotPast` and `isOnGoing` to include events that happen today.

The `startsAfterDate`, `endsBeforeDate`, `isDuringDate` and `isNotDuringDate` methods accept a date as the first argument, followed by the field handle and entry type handle:

```
{# Entries starting after a specific date #}
{% set events = craft.entries.section('events').startsAfterDate('2025-06-01', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}

{# Entries ending before a specific date #}
{% set events = craft.entries.section('events').endsBeforeDate('2025-12-31', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}

{# Entries overlapping with a single date #}
{% set events = craft.entries.section('events').isDuringDate('2025-06-15', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}

{# Entries overlapping with a date range #}
{% set events = craft.entries.section('events').isDuringDate('2025-06-01 => 2025-06-30', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}

{# Entries NOT overlapping with a date range #}
{% set events = craft.entries.section('events').isNotDuringDate('2025-06-01 => 2025-06-30', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}
```

### Field values

[](#field-values)

When using the field in your template, you have access to both `start` and `end` properties, as well as:

- `getFormatted()`: which optionally accepts a date(time) format (eg: 'd/m/Y') as the first parameter and a seperator string as the second (eg: ' until ').
- `isPast`: returns `true` if the `end` property is past the current date &amp; time.
- `isFuture`: returns `true` if the `start` property is ahead the current date &amp; time.
- `isOnGoing`: returns `true` if the `start` property is past the current date &amp; time *and* the `end` property is ahead of the current date &amp; time.
- `isNotPast`: returns `true` if the `end` property is ahead of the current date &amp; time.
- `startsAfterDate(date)`: returns `true` if the `start` property is after the given date.
- `endsBeforeDate(date)`: returns `true` if the `end` property is before the given date.
- `isDuringDate(date)`: returns `true` if the date range overlaps with the given date or date range.
- `isNotDuringDate(date)`: returns `true` if the date range does not overlap with the given date or date range.

The `isDuringDate` and `isNotDuringDate` methods accept a single date string, a date range string (using `=>` as separator), or an array with `start` and `end` keys:

```
{% if entry.dateRangeField.isDuringDate('2025-06-15') %}...{% endif %}
{% if entry.dateRangeField.isDuringDate('2025-06-01 => 2025-06-30') %}...{% endif %}
{% if entry.dateRangeField.isNotDuringDate('2025-07-01 => 2025-07-31') %}...{% endif %}
```

### `getFormatted()`

[](#getformatted)

When using the `getFormatted()` function, you can pass paramters in 2 ways:

1. a date format and a separator string (eg: `entry.dateRangeHandle.formatted("d/m/Y Hi", "until"|t)`)
2. an array with a `date` and a `time` key and a separator string (eg: `entry.dateRangeHandle.formatted({ date: 'd/m/Y', time: 'H:i:s'}, 'tot'|t)`)

With this second option, the field can output date and time seperatly and when the start and end dates are the same, it will only ouput one, using the separate time formates for the start and end times (eg ` 30/04/2020 11:00 until 16:00` )

GraphQL
-------

[](#graphql)

The field has full support for Craft's GraphQL api, which was added in Craft CMS 3.3 You have access to the same properties as you do in Twig, and you can also use Craft's `@formatDateTime` to change the date formats.

```
query{
  entries(
   section: "events",
   isFuture: ["dateRangeFieldHandle", true]
  ) {
    title
    ... on events_events_Entry {
      dateRangeFieldHandle {
        start
        end @formatDateTime(format: "d M Y")
        isPast
        isOnGoing
        isFuture
      }
    }
  }
}
```

The following GraphQL query arguments are also available: `startsAfterDate`, `endsBeforeDate`, `isDuringDate`, and `isNotDuringDate`.

```
query{
  entries(
   section: "events",
   isDuringDate: ["2025-06-01 => 2025-06-30", "dateRangeFieldHandle", "entryTypeHandle"]
  ) {
    title
  }
}
```

---

Brought to you by [Studio Espresso](https://www.studioespresso.co)

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance75

Regular maintenance activity

Popularity35

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.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 ~89 days

Recently: every ~166 days

Total

27

Last Release

76d ago

Major Versions

1.2.2 → 2.0.02019-12-12

2.5.0 → 3.0.0-beta.12022-03-02

3.0.1 → 5.0.0-beta.12024-03-23

PHP version history (2 changes)5.0.0-beta.1PHP 8.2.0

5.0.0-beta.2PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![janhenckens](https://avatars.githubusercontent.com/u/755428?v=4)](https://github.com/janhenckens "janhenckens (136 commits)")[![denisyilmaz](https://avatars.githubusercontent.com/u/4189607?v=4)](https://github.com/denisyilmaz "denisyilmaz (3 commits)")[![bartrylant](https://avatars.githubusercontent.com/u/1434451?v=4)](https://github.com/bartrylant "bartrylant (2 commits)")[![MrHesus](https://avatars.githubusercontent.com/u/25330441?v=4)](https://github.com/MrHesus "MrHesus (1 commits)")

---

Tags

cmsCraftcraftcmscraft-plugindate-range

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/studioespresso-craft-date-range/health.svg)

```
[![Health](https://phpackages.com/badges/studioespresso-craft-date-range/health.svg)](https://phpackages.com/packages/studioespresso-craft-date-range)
```

###  Alternatives

[verbb/navigation

Create navigation menus for your site.

90683.7k17](/packages/verbb-navigation)[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[verbb/comments

Add comments to your site.

13753.1k](/packages/verbb-comments)[verbb/tablemaker

Create customizable and user-defined table fields.

40168.8k1](/packages/verbb-tablemaker)[supercool/tablemaker

Create customizable and user-defined table fields.

40141.7k](/packages/supercool-tablemaker)[pennebaker/craft-architect

CraftCMS plugin to generate content models from JSON/YAML data.

72148.5k5](/packages/pennebaker-craft-architect)

PHPackages © 2026

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