Date Filter is one of Sitecore SXA search filter components. It allows user to narrow search results by item date field. Here are use cases I put together to use this single component without creating additional custom date filter.
The SXA Date Filter takes From and To date as inputs
A – One date field: For example, news normally has only one date field.
Create a facet item based on news date field, then all above 3 use cases can be achieved by regular setting of date filer.
B – Two date fields: For example, Event has start and end date. We need to search all events which active period overlapping a certain date range.
1, Event Start date is less than From-Date and End date is between From-Date and To-Date
2, Event date period covers From-Date and To-Date range
3, Event Start date is between From-Date and To-Date and End date is greater than To-Date
4, Event start and end date are between From-Date and To-Date
The Date Filter has From and To input boxes, but it can’t accommodate above scenarios as it takes only one date facet. How to achieve above 4 use cases with 2 date facets, the trick is, using combination of 2 Date Filters to query Events as 4 use cases all meet following criteria:
end date > From-Date and start date < To-Date
First date filter: Select EventEndDate facet and hide To-Date box.
Second date filter: Select EventStartDate facet and hide From-Date box.
After above setting, we will get date filters like below. It narrows down search results to all the active events between From and To date.