After searching the web community for an event filter between two dates I decided to write this tutorial to help others like me who had a some challenges finding how to do it.

It is tempting to believe that using the "is between" on a date fields will work. However, this option is used only in the case of events "Starting" on a rage of date.

This module (https://www.drupal.org/project/views_between_dates_filter) is used to filter evenst on ONE date and NOT a range of date (as the image suggest).

The following conversations have guided me to this tutorial.
https://www.drupal.org/node/1302940
http://drupal.stackexchange.com/questions/36380/drupal-7-views-filter-be...

This tutorial requires that you already have a content type with a date field . It is not necessary to have two fields to adjust an "end date" for the event, only a date field with the "Collect an end date."

This part (which seems "logical" to start - but it is not so much) is the basis of this discussion.
Take for example this figure, based on the discussion of https://www.drupal.org/node/1302940
figure1

A search filter between the 1th and 31th of July should provide us the events A, B, C and D (shaded area), and Exclude E and F.

If we have a filter with a Date field (based on the Start date) using the option "is between" will only show B and C since their "start date" is between those dates, but will exclude events A and D since their "start date" is before the desired search . This is not the desired result, we want to include them in the results.

The following conversation https://www.drupal.org/node/1302940 explains:

event end date >= user start date
AND
event start date <= user end date

Following this, we must swap the "Start date" and "End date" to the users. Users will not notice but it is crucial to obtaining the desired results.

To include events A and D in this search, we will need two filters exposed to our Views (again: based on the same field and not two separate fields)
In this order:

1. Date - end date (field_dates:value2)
2. Date - start date (field_dates)

In " Date - end date (field_dates:value2)", Select popup as form element,
Figure2

Next window:
Exposed this filter to visitor

Even though this label says "End date", we are going to make believe this is the "Start date", so change this label to "Start Date" instead.
figure3

Change the operator to "Is greater than or equal to", leave the "Select a date" as is. (event end date >= user start date)
figure4

Do the same to the second filter:

Date - start date (field_dates)
- change this label to "End Date",
- Select popup as form element,
- Exposed this filter to visitor

This time Change to operator to "Is less than or equal to", leave the "Select a date" as is. (event start date <= user end date)

Last suggestion: Make sure that you have "AND" between those two operators.

figure5

Save everything, Enjoy...

Hope this helps someone along the Drupal mystical path.. Sorry for any typo or grammatical mistake, English is not my native language.

Feel free to comment or correct me, I'll adjust.

AttachmentSize
Relative Dates25.55 KB

Comments

Elvin - Albania Drupal Developer’s picture

Hello

I have this use case:

I have a content type with a start/end date.
I want to filter nodes like this:

Show nodes if TODAY is in the daterange (start-end date of the node).
Any idea on how to achieve this?

LBiStockholm’s picture

It's a two step filtering:
End date >= today
Start date <= Today

samirjamal’s picture

incase the start date and end date with same date is not working,
it not get only the nodes of one selected day,( it gives no records)

hockey2112’s picture

This does not work as expected. I have a view of Commerce orders, and I need to add an exposed filter to filter the orders by date range. I have added two exposed filters for Order: Placed. One filter is "greater than or equal to" for the start date, and the other filter is "less than or equal to" for the end date. I also have Date Popup module installed.

When I choose May 15, 2022 as my start date and May 16, 2022 as my end date, it only shows my orders on May 15. If I change the end date to May 17, 2022, it shows my orders from May 15 and May 16 (but not from May 17).

The orders from the "End" date are being excluded. I assume this a function of time of day... for example the date filter appears to assume the time to be "00:00:00" on each of those two dates I select. If this is the case, that would likely be why the end date orders are excluded, because they are placed after 00:00:00 on that date. How can I resolve this issue?

Freddy Rodriguez’s picture

In case of relative dates:
relative date filter views

harrick’s picture

Does this guide use the basic date field or the datetime range field? As I can't seem to make this work with the latter. I've added two exposed filters from the same date range field. I expected to be able to select the range end date for one filter. However, both filters seem to reference just the range start date.