Building a Drupal view with exposed date range filters
Views turns a content collection into a searchable directory. An exposed filter lets visitors narrow a result set from the page, while editors retain control of the query, fields, access rules and presentation. For date-based listings, the useful pattern combines a date filter, clear boundary labels and a deliberate timezone policy.
This example follows an events listing built with core Views. Each event has a title, an all-day date, a suburb, a city and a publication status. Visitors choose a start and end date, then see matching events. The same approach works for publication dates, booking availability, grant submissions or internal review queues; only the content type and field selection change.
Australian sites face several time zones. Sydney and Melbourne observe AEDT during daylight saving, Brisbane remains on ACST and Perth uses AWST. Dates are commonly displayed as day/month/year, and an all-day event should stay on its intended civil date rather than jump because a timestamp crosses midnight.
A reliable build decides whether boundaries are inclusive, which timezone converts values, how undated content behaves and what appears when one boundary is blank. Keep those rules aligned with the purpose: a council events directory, ticketing business and membership portal may expose similar controls but need different behaviour.
Planning the view around a real use case
Start with the content model rather than the filter form. A dedicated Event content type can use a plain Date field for an all-day event or a Date and Time field when doors, sessions or deadlines matter. Make the date required when every result must have one. For multi-city events, add a city or event timezone field so the displayed time remains unambiguous.
Create a Views page, restrict it to the Event content type and keep unpublished content excluded. Add Title, Event date, City and Suburb as fields, then sort by Event date ascending with Title as a secondary sort. A stable date order matters more than a visually elaborate card layout because users scanning a calendar expect the next available date first.
Plan access before exposing the form. Anonymous visitors should see only content that published roles can view, and privileged preview items should not leak through the exposed query. Choose a plain URL such as /events and decide whether filtered pages retain the same path. These choices keep the View predictable for editors, search engines and people sharing a filtered link.
Creating and exposing the date filters
In Drupal’s admin interface, open Structure, then Views and add a new view for content. Set it to show Event content types, keep the published-content rule, and add Title and Event date to the display. Open the view’s Filter criteria and add Event date. Select the date-range or Between operator, check Expose filter, and give it a label such as Event date range.
Confirm the exposed control before styling it. Some Drupal versions present both start and end inputs for a Between criterion; others produce a single date input. If a true two-ended control is unavailable, create two exposed filters on the same field: Greater than or equal to for the start and Less than or equal to for the end. They can remain independently blank and still behave like a conventional date-range search.
Use the Exposed Filter Form section to choose a simple form style, provide a short description and give each criterion a stable identifier where the interface supports it. Test the page and record the query-string names Drupal generated rather than hard-coding field machine names. The site’s background on Drupal Woo is also a useful reference when checking Drupal-specific naming and configuration conventions.
Handling time zones and local dates
Timezone handling is where an otherwise correct View can return surprising results. Set the site timezone to the intended operating zone, such as Australia/Sydney, and check whether the date filter uses the website or user timezone. Date and Time fields are stored and compared consistently by Drupal, then converted for display; visitors in Brisbane can therefore see a different local time from visitors in Melbourne.
Daylight saving makes the boundary visible. On the first Sunday in October, Sydney and Melbourne move from AEST to AEDT, while Brisbane and Perth keep their standard offsets; the clocks return in April. An all-day event represented as a timestamp can shift to the previous or next civil date. A plain Date field avoids that problem because the value describes a calendar day rather than an instant.
For a national directory, choose deliberately. User-timezone filtering can make sense when people search their own working hours, but it means the same URL can include different events for different visitors. If each event belongs to a city and represents a local calendar day, keep a date-only field and add City as another exposed facet. Timed events need an explicit timezone in their label and may require separate views or a custom calculation.
Refining range logic and edge cases
Boundary behaviour must be tested against real records. A visitor should expect an event on 12 July to appear when From is 12 July and To is 12 July. Most core Between implementations include both boundaries, but confirm this in the installed Drupal version. Two separate greater-than and less-than filters give explicit control and avoid relying on an ambiguous range widget.
Leaving one side empty is useful for open-ended browsing: From may be blank while To asks for events up to a date, or the reverse. A Between criterion may require both values, so two filters are often easier for editors and visitors to understand. Use the same field, conversion rules and granularity for both criteria; mixing a plain Date field with a timestamp would compare unlike values.
Content without a date needs a separate policy. If Event date is optional, adding the range criteria directly will usually exclude those nodes. Use an OR group that permits either a date within the range or an empty date, or publish undated content in a separate view. For an events directory, making the date required is usually the cleanest rule because a calendar result with no date has little practical value.
Designing the filter form for users
The exposed form is part of the interface, not just a query control. Label the fields From and To, explain that results include events on either boundary, and retain the selected values when the form is submitted. Although browsers in Australia commonly offer a day/month/year picker, the display format must not be the only protection against ambiguous numeric entry.
Check the generated form with a keyboard and a screen reader. Every input needs a visible associated label, the date-range controls need a logical reading order, and error messages must identify the affected field. Keep the Apply or Filter button, or provide an equally clear alternative if JavaScript submits the view automatically. Announce the updated result count without moving keyboard focus unexpectedly.
Views can render exposed filters in a block or inline above the results, while the form style affects their arrangement. Use theme CSS to create a responsive two-column range on wide screens and a stacked layout on phones. Scope selectors to the View’s form or region so a generic form-control rule does not unexpectedly restyle other Drupal forms. Keep the visual treatment consistent with the site’s component library.
Testing the view across Australian scenarios
Build a small set of test records before testing the View. Include dates on both sides of midnight, leap day, the first and last day of a month, and a weekday event during an Australian public holiday. Public holidays differ across the states, while major events such as the Melbourne Cup affect local demand and scheduling.
Test the boundary combinations systematically: both dates blank, only From, only To, equal start and end values, reversed dates and invalid text. Repeat the checks as an anonymous visitor, an authenticated member and an editor. Clear Drupal’s caches when a configuration change appears not to take effect, and check that pagination, sorting and exposed filters coexist without losing submitted values.
Privacy and consumer-law duties apply to the data and context around the View. A date range alone does not identify a person, but combined customer filters and URL logging can expose personal information. For organisations covered by the Privacy Act 1988, collection and retention should align with the Australian Privacy Principles. In the Australian ticketing market, the Australian Consumer Law also makes it important that filtered availability, prices, cancellation terms and refunds remain clear and accurate.
Comparing, publishing, and maintaining the view
Different combinations suit different directory rules, and the field type usually matters more than the appearance of the control.
| Pattern | Suitable use | Main consideration |
|---|---|---|
| One exposed Between filter | Compact core View with both bounds required | Confirm inclusive endpoints and timezone conversion |
| Two exposed date filters | Visitors may leave either bound blank | Use matching operators and identify each field clearly |
| Date-only field | All-day events in different cities | Prevents daylight-saving date shifts |
| Site-timezone date and time | Service operating in one zone | Gives predictable conversion for every visitor |
| User-timezone date and time | Viewer-specific scheduling searches | The same URL can produce different results |
For this example, Event date is a required plain Date field. Two exposed criteria provide the clearest open-ended range, although a Between filter is suitable when both values are mandatory. The following checks keep that behaviour explicit:
- Confirm that 12 July appears for identical start and end dates.
- Check start-only, end-only and reversed-value behaviour.
- Confirm the date field, timezone setting and filter operators match.
- Verify labels, query parameters and keyboard submission.
After release, editors also need a repeatable maintenance routine:
- Keep representative boundary records available for regression testing.
- Review filter performance before adding more content types.
- Recheck boundary behaviour after a Drupal or contributed-module update.
- Document which site timezone and date-field type the View uses.
The completed listing gives Australian users a predictable calendar search while preserving the editorial control needed when events, time zones and site data change.