How to filter a View by Date Range (start, end)?

Solutions

Currently Views is not very aware of date ranges. It can filter on the start or end date as separate filters but not the date range as a whole.

To enable filtering based on the date range I created the module Views Date Range Filters. Currently it has 3 additional filters for Datetime Range fields:

Includes

Filters by date ranges which include the supplied date.

Overlaps

Filters by date ranges which overlap with the supplied date range.

Ends by

Filters by date ranges which end by the supplied date. Equivalent to "End date <= supplied date". Useful for grouped filters when using "Start date".

Surprisingly this is not possible with Drupal 8 yet. But there is a long history of trying to make it work: https://www.drupal.org/node/2786577 The last patch, you find in this post, seems to work. You can download and apply it, using the following commands:

wget https://www.drupal.org/files/issues/improve_the_views-2786577-76-core.patch
git apply improve_the_views-2786577-76-core.patch

If git isn't available on your server, try:

patch -p1 < improve_the_views-2786577-76-core.patch

TO apply the patches you have to navigate to the core folder first. And be aware that you have to reapply this patch, after committing a core update. (This sucks!) So let us hope, the Drupal Gods will get this into core soon!

Using interval-filter plugin you can choose two fields to be used respectively as minimum and maximum date, this introduces the concept of range. Then you can filter the views by specifying a date that must be contained or not contained in the range.

Take a look at: https://github.com/barsan-ds/interval-filter for examples

Tags: Views / Drupal 8 / Datetime

Similar questions

How do I change the date format depending on Start and End date in Drupal 7
I have a content type called 'Events' including the fields: I have created a view that takes this content type and outputs it as follows: My question is how can I can change the output of the field if the 'Date' field has a start date and an end date. I am using the Event Calendar Module to create my events. Can you offer a solution? Thanks in adva...
Fetch discount start date and end date
I have a discount 'women's day'. I have set start and end date as 8March 8AM to 8 March 8PM for this discount. In my coupon validation function, I want to check if the current time is in between 'women's day' discount start and end time or not. So I basically need a start and end time of discount.
Partial start date with end date output views
I'm using views to output a list of nodes with dates. Some node dates have both a start and end date inserted. If both a start and end date exists, i would like the date to be outputted only taking the day from the start date. Current: 9 January 2018 - 10 January 2018 Desired: 9 - 10 January 2018 I've tried using a custom field and rewriting the re...
How to retrieve value of start date with format end date?
I D8 installed the module Optional End Date in order to add an optional end date within a date field. When I had a single date field value I could get the value by using: If I change this in the new field name: I get back NULL. How should I get this value?
Combining Date Start and Date End in Drupal 8 Views Block
I am new to Drupal 8 Views - How do you concatenate Event Start Date Sept 1, 2019 with Event end Date ie: Sept 4, 2019? The end result is they just want the Month and Day to show up like this Sept 1-4.
Webform Start Date and End Date
I'm having a heck of a time setting the start date and end date for a Webform. We've got a node with a webform entity reference field that generates a new Webform. On that node form, we want to give people the option to set the new form's status. Here's a trimmed-down look at our code (I've omitted most of the superfluous stuff)... Without setting ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.