Natural date adds a date field that takes as much of a date as the editor knows: a year, a month, a day, or a date and time. Editors type 1992, April 1992 or 5 April 1992, and each date is shown at the detail it was typed with: 1992 never shows a month, and 5 April 1992 never shows a time.
The field stores a real datetime, as the core field does, plus precision and the time zone. Views filters, sorts and date arguments work as on core date fields.
Features
- A single text box: editors type the date the way they know it, in any form PHP's date reading understands.
- Precision per value, not per field: one field holds years, months, days and times side by side.
- The "Adaptative date format" formatter lets you choose which of the site's date formats to use, and shows each date with the most detailed of them that shows nothing finer than is known of the date. It works on any date field: natural dates, core dates, and timestamps such as "Authored on".
- Multilingual: month names, full or abbreviated, are read in the site's interface language as well as in English, so on a Spanish interface
abril 1992and5 abr 1992work. Dates are shown with month and day names in the language of the content. - Core date formatters (Default, Custom, Plain, Time ago) also work on the field.
- Values set from code, migrations and JSON:API are read the same way as typed ones.
Example of dates
- A year:
1992 - A month:
1992-04,April 1992,Apr 1992 - A day:
1992-04-05,5 April 1992,April 5, 1992,17-04-1992 - An hour or a minute:
1992-04-05T10,1992-04-05 10:00, optionally with a time zone:1992-04-05 10:00 Europe/Madrid,1992-04-05T10:00+02:00,1992-04-05T10:00Z
How much of the date was typed comes from the numbers and month names typed, so April 1992 stays a month. The order of day and month differs between countries: a middle number above 12 is read as the day (1992-22-04 is 22 April 1992), otherwise 05-04-1992 is read day first, as PHP does. A range of months is read as its start: May-August 1992 is May 1992. Slashes, seconds and two-digit years are rejected.
A time typed without a time zone works as in core: it is read in the current user's time zone. A typed time zone is kept, and the time is shown again in it.
Configuration
Natural date field and formatter
- Add a "Natural date" field from the "Date and time" group on any entity type.
- Set "Date type" to "Date only", or to "Date and time" to also accept times.
- On "Manage display", choose the "Adaptative date format" formatter and tick one date format per level of detail, including one that shows only the year.
- Optionally, set "Time zone override" to show times in one time zone instead of the viewer's. Dates without a time are never converted.
Formatter only, on an existing date field
- On "Manage display" for an entity type with a date field (a core "Date only" or "Date and time" field, or a timestamp such as "Authored on"), choose the "Adaptative date format" formatter.
- Tick the site date formats to use, one per level of detail, including one that shows only the year. A "Date only" field is shown with the most detailed ticked format down to the day, and a "Date and time" field or a timestamp with the most detailed ticked format overall.
- Optionally, set "Time zone override" to show times in one time zone instead of the viewer's.
Ask your assistant about Natural date
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- datetime Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.