Useful Drupal modules and options for date and time formatting

07 Jan 2021

Collection of Drupal modules for optimal date and time formats

There are plenty of ways to display the same date and time on your website. Do you prefer the 12-hour or the 12-hour format? Would you like to include the day of the week? Or maybe you want to specify the start and end date and time? The choice of the format may depend on preferences and conventions that exist in different countries, as well as the specific website use cases and requirements.

Of course, Drupal provides different ways to display the date and time in the needed ways. Let the Golems team offer you an overview of date and time formatting options for Drupal websites. This will include the Drupal core capabilities, as well as a bunch of cool contributed modules.

Drupal date and time format modules and options

1) The Drupal core functionality for date and time

Drupal’s built-in date and time formatting capabilities have become much richer than they used to be in earlier Drupal versions, so there is less need for any extra modules. In Drupal 7, there was the Date contributed module that gained a big popularity. The Drupal 8 Date became unnecessary as a separate module, because its functionality was included into the Drupal 8 core, so we got Drupal 8 Datetime as the Date’s successor.

Both in Drupal 8 and Drupal 9, the core includes the Datetime and Datetime Range modules. The Drupal Datetime module is the main one that it is responsible for providing the datetime field type and defining datetime form elements. The Datetime Range module adds the ability to store the end date as well.

The useful date modules, widgets, and formatters provided by the Drupal 8/9 core make it easy to play with the ways the date and time are displayed on your website.

Using the key Drupal core date and time formatting

There are plenty of formats out-of-box for you to choose from. They are found on the Configuration -> Regional and Language -> Date and Time Formats tab. You can choose anything from a default long date (e.g. “Monday, December 28, 2020 - 12.00) to just a year (e.g. 2020).

However, to have even more flexibility, you can create your own format right there on that tab using the PHP syntax. There are characters for the date, time and time zone, for example:

  • “D” is the three-letter textual representation of a day of the week (e.g. “Sun”)
  • “l” is the same but written in full ( “Sunday”)
  • “d” is the 2-digit day of the month (e.g. “25”)
  • “A” is the uppercase Ante Meridiem and Post Meridiem (AM and PM)
  • “T” is the Time Zone abbreviation (e.g. EST, MDT)

and so on.

You just click “Add format” on your Drupal’s Date and Time Formats tab and compose the new format as you like. Drupal will immediately show you how this will be displayed. Of course, the Drupal UI is for convenience, and any developer can always set Drupal 8 date fields programmatically.

Time formats can be added to date fields of your content types in Structure -> Content Types -> [ Your content type ] -> Manage Display. In addition to the four main field formatters (plain, time ago, custom, default) next to each date field, you can select any of the formats you have on your Date and Time Formats tab.

Setting your Drupal time zone

Right there, under Configuration -> Regional and Language, you will find the Regional settings tab where you can specify your site’s time zone, as well as check or uncheck the option for users to set their own time zone.

2) Contributed Drupal modules for date and time

Extra modules add their own tweaks and tricks to how your date and time can be displayed. Here is a collection of some of the most interesting ones for Drupal 8, most of which are already compatible with Drupal 9.

Smart Date

With the Smart Date module, you can do more refined formatting and benefit from the smart autofill functionality. For example, it’s enough to set the duration of some event and the start date and time — the end date and time will be filled automatically. You can set different duration options and expose them to the content creators so they can easily switch between them. It’s also possible to set the default duration, zero duration, all day duration, and more.

AP Style Date

The style matters for the AP Style Date module — it displays the date fields according to the AP Stylebook (The Associated Press Stylebook). Among its requirements are the numerical figures (without "st," "nd," "rd," or "th"), fully capitalized city names in datelines, capitalized and unabbreviated days of the week, the time/date/place order, and so on. To use this styling, you need to set your field formatter to "AP Style."

Calendar

The Calendar module allows you to create calendars by presenting the date fields of Drupal Views in the calendar format. This includes CCK date fields, the dates of node creation or update. It’s possible to choose between the day, month, and year view modes. Your Drupal website’s users can conveniently navigate through the calendar with the help of the “previous” and “next” links.

Field Timer

Whenever you need to display a timer or a countdown, the Field Timer module comes for help. It extends the core module Datetime module with three special field formatters. One of them is simple text and the two others are based on the County and jQuery Countdown jQuery plugins.
The module is very configurable and allows you to change effects, backgrounds, formats, languages, and more.

Datetime extras

As the name suggests, the Datetime extras module extends the core Datetime and Datetime Range modules with extra capabilities. For this purpose, it provides a set of widgets and formatters. Among them are the widgets to set date and time range with duration, to select date only with no time from the select list, etc.

Date range formatter

The Date range formatter is a popular Drupal module that creates a field formatter for your Drupal website’s date fields. This field formatter displays the date ranges based on the preconfigured format.

Age Field Formatter

If you need to display the age instead of the birth date, the Age Field Formatter module will do the conversion for you. This works through a special field formatter provided by the module. You can have the age alone or both the age and the date displayed on your website. The “years” suffix can be added to the age value.

Formatter Suite

The Formatter Suite module adds as many as 18 field formatters to present various types of data. The suite includes the formatters for the date and time such as the date and time list, the custom date and time list, and the time ago list. It also has formatters for timestamps.

The date and time is perfect for contacting us!

Need help displaying the date and time in the required formats on your website? You are welcome to contact the Golems Drupal development team at any time or date. However, if you choose “today” and “now,” we could start fulfilling your requirements and delivering the results as soon as possible.

Ready to give you a quote,
your Golems

Comments

An
Anonymous
1 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.