Datetime Extras
Extends core Datetime and Datetime Range modules with additional field types, widgets, and formatters for more flexible date/time handling.
datetime_extras
Install
composer require 'drupal/datetime_extras:8.x-1.2'
Overview
The Datetime Extras module provides additional functionality to extend the core Datetime and Datetime Range modules. It adds a new "Time Only" field type for storing time values without dates, as well as several enhanced widgets for datetime and date range fields.
Key features include a duration-based date range widget that allows content creators to specify an end time as an offset (duration) from the start date/time rather than an absolute end time. It also provides a date-only select list widget that removes time selection when only the date is relevant, and a configurable datetime widget with customizable year ranges and time increments.
Features
- Time Only field type that stores time values without date components, useful for schedules, business hours, or recurring time-based events
- Date and time range with duration widget that allows content creators to specify either an absolute end date/time or a duration offset from the start time
- Select list, no time widget that displays datetime fields using select lists for date components only, hiding unnecessary time selection
- Configurable Date and time widget with customizable year range limits and time increment settings for HTML5 date inputs
- Time Only widget providing a clean time-only input interface for the Time Only field type
- Automatic duration granularity adjustment for date-only vs datetime fields
- Support for various date part order options including Year only, Month/Year, and Year/Month combinations
Use Cases
Event scheduling with flexible duration
When creating events, content editors can specify a start date/time and then choose to either set the end time directly or define the event duration. For example, a recurring meeting might always last 1 hour, so editors can simply select '1 hour' duration rather than calculating and entering the end time manually each time.
Business hours management
Use the Time Only field type to store opening and closing times for businesses without associating them with specific dates. This is ideal for displaying store hours, appointment availability windows, or service time slots.
Historical date entry with year-only selection
For content types that need to capture historical dates where only the year matters (like birth years, founding dates, or publication years), use the Select list, no time widget configured with Year only (Y) date order. This simplifies data entry and avoids confusion about unknown months or days.
Date-only fields without time clutter
When a datetime field is used but time is irrelevant (like publication dates or event dates), the Select list, no time widget removes time selection entirely, providing a cleaner interface for content editors.
Configurable date ranges for different content types
Use the Configurable Date and time widget to restrict date selection to appropriate ranges. For example, a 'Date of Birth' field might use '-120:+0' to only allow past dates, while a 'Future Event Date' field might use '+0:+10' to only allow dates in the next 10 years.
Multi-day event creation
For conferences or multi-day events, the Date and time range with duration widget configured for date-only fields allows editors to specify '3 days' as the duration, automatically calculating the end date. The widget handles the human-friendly counting (Day 1 through Day 3) vs computer offset calculation.
Tips
- When using the Date and time range with duration widget with date-only fields, the granularity is automatically limited to days only (hours, minutes, seconds options are hidden)
- The Select list, no time widget inherits settings from core's DateTimeDatelistWidget but adds extended date order options (Y, MY, YM) for more flexible display
- For the Configurable Date and time widget, use relative year ranges like '-50:+50' to automatically adjust as time passes, or absolute ranges like '2020:2030' for fixed boundaries
- The Time Only field stores values in the standard datetime storage format but only the time component is meaningful - the date portion is automatically generated
- Duration Field module is only required if you want to use the duration-based widget; other features work without it
Technical Details
Hooks 2
hook_help
Provides help text for the module's help page at /admin/help/datetime_extras
hook_field_widget_info_alter
Conditionally removes the daterange_duration widget if the Duration Field module is not installed or is an older incompatible version
Troubleshooting 4
Ensure the Duration Field module (version 8.x-2.0-rc3 or higher) is installed and enabled. The widget is automatically hidden if Duration Field is not available or is an older incompatible version. Install it with: composer require 'drupal/duration_field:^2.0' && drush en duration_field
The Time Only widget includes custom validation to handle time-only values. Ensure you're using the Time Only widget (time_only_field_default) with Time Only fields. The widget adds the necessary DrupalDateTime object that core validation requires.
The module adjusts duration display for date-only fields to match human counting (1-based). A 3-day event starting Monday and ending Wednesday displays as '3 days' duration, but internally stores a 2-day offset. This is intentional behavior.
If you see deprecation warnings for DateConfigurableListWidget, migrate your fields to use the 'Select list, no time' (datetime_datelist_no_time) widget instead. The deprecated widget will be removed in version 8.x-2.0.