Views Date Filter

Enhances Drupal Views date and datetime filters with date pickers and improved user experience for exposed filters.

date_filter
5,539 sites
27
drupal.org

Install

Drupal 11, 10, 9 v1.0.2
composer require 'drupal/date_filter:^1.0'

Overview

The Views Date Filter module is a plug-and-play solution that enhances date and datetime filters in Drupal Views. It seamlessly replaces core filters with improved versions, providing a more user-friendly experience when exposed to end users.

This module addresses common pain points with core's date filtering in Views by replacing the default text input fields with proper HTML5 date pickers. It also improves labeling for between operators (using "from" and "to" instead of "min" and "max") and automatically maps offset default values to actual dates in the exposed filter date pickers.

The module works transparently by altering the core Views filter plugins for both 'date' (timestamp-based fields like "Authored on") and 'datetime' (Datetime field types), making it easy to upgrade existing Views without configuration changes.

Features

  • Replaces core date and datetime Views filters with enhanced versions that use HTML5 date pickers for exposed filter value selection
  • Improves field labels for between/range operators by using "from" and "to" labels instead of the less intuitive "min" and "max" labels
  • Supports both date-only mode and date-time mode, allowing filter configuration to include or exclude time selection
  • Automatically maps offset default values (like "-1 month" or "+1 day") to actual dates in exposed filter date pickers, making default values more intuitive for users
  • Proper timezone handling for datetime fields, respecting both storage timezone and user timezone settings
  • Removes obsolete input type selection (offset vs date) that was confusing in core filters
  • Supports all standard comparison operators: equals, not equals, less than, greater than, less than or equal, greater than or equal, between, and not between
  • For date-only filters with equals operator, automatically handles full-day range matching (00:00:00 to 23:59:59)

Use Cases

Content filtered by publication date with date picker

Create a View listing content with an exposed 'Authored on' filter. After enabling this module, the exposed filter will display a date picker instead of a text field, making it easy for users to select dates without knowing the required format. Set the operator to 'greater than' and default value to '-1 month' to show recent content by default.

Event listing with date range filter

For an events listing with a datetime field, add a filter with 'between' operator and expose it. Users will see 'from' and 'to' date pickers allowing intuitive date range selection. Both date pickers work seamlessly for finding events within a specific time period.

Finding content from a specific date

Use the equals (=) operator on a date filter when you want users to find all content from a specific day. The module automatically expands this to cover the full 24-hour period (00:00:00 to 23:59:59), so users don't need to specify times.

Archive view with month/year presets

Create an archive view using offset values like '-1 month', '-3 months', or '-1 year' as default values. The module converts these offsets to actual dates in the date picker, so users see a meaningful starting date rather than cryptic offset text.

Timezone-aware datetime filtering

For international sites where datetime fields store data in UTC but display in the user's timezone, the module properly handles timezone conversion. Filters work correctly regardless of the user's timezone setting, converting input from user timezone to storage timezone for accurate queries.

Tips

  • The filter type setting (Date vs Date and time) in the View filter configuration determines whether time pickers are shown alongside date pickers for exposed filters
  • When using between operators, you can leave either the 'from' or 'to' value empty to create open-ended ranges (e.g., 'all content before' or 'all content after' a specific date)
  • Offset values like '+1 day', '-2 weeks', or '-1 month' work as default values and are automatically converted to actual dates when displayed to users
  • For datetime fields configured as 'Date only' in field settings, the time picker will be automatically hidden even if you select 'Date and time' filter type
  • The module uses HTML5 native date and time inputs, which may render differently across browsers but provide the best user experience for each platform

Technical Details

Hooks 2
hook_views_plugins_filter_alter

Alters the Views filter plugin definitions to replace core's date and datetime filter classes with the module's improved versions.

hook_help

Provides help text for the module explaining its features and improvements over core date filters.

Troubleshooting 4
Date picker not appearing on exposed filter

Ensure the filter is properly exposed in the View configuration. The date picker only appears for exposed filters; non-exposed filters continue to use text input to support offset values like '+1 day'.

Timezone issues causing wrong results

For datetime fields, ensure your Drupal site timezone settings are correct at /admin/config/regional/settings. The module respects these settings when converting between user input and database storage (UTC).

Filter not working after module installation

Clear all caches using 'drush cr' or the Performance page. Views may cache filter plugin information that needs to be refreshed after the module replaces core filters.

Time portion being ignored in filters

Check the filter configuration in your View. If 'Date' type is selected instead of 'Date and time', times will not be considered. Also verify the field itself supports time (datetime vs date-only field).