April 16, 2025
This post piggybacks on my earlier post "Print raw values from Smart Date fields in Twig templates - Drupal 8+".
The Drupal Smart Date module allows users to choose a timezone for each date entered in a Smart Date field. One of my clients has a site with an event content type that uses a Smart Date field, and they needed event dates and times to display in the actual timezone entered. However, no…
Continue reading Drupal & Twig: How to show Smart Date dates in the created timezone, without conversion to site default or user-chosen timezone
October 26, 2023
This is a followup to my post "Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8". For more on working with Smart Date timezones, see "Drupal & Twig: How to show Smart Date dates in the created timezone, without conversion to site default or user-chosen timezone".
That post deals with core Drupal Date and Daterange fields.…
Continue reading Print raw values from Smart Date fields in Twig templates - Drupal 8+
October 23, 2020
I wanted to change the format of the comment submitted timestamp on my blog, and figured it could be done in Twig - but nope. There's an active issue on Drupal.org to allow the format to be changed in the UI, but until that's done, you need to use a theme preprocess function.
function THEMENAME_preprocess_comment(&$variables) { $date_formatter = \Drupal::service('date.formatter…
Continue reading Change format of comment created date - Drupal 8 & 9
May 21, 2019
(Also see my post on how to get individual values from Smart Date fields).
I've been working on a site with events, and tearing my hair out over how to print formatted dates with the correct timezone value in Twig templates, specifically node.html.twig and views-view-fields.html.twig.
The issue was first, getting the formatted date to display in the template; and secondly, when I managed to get…
Continue reading Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8