Drupal 8 – Formatting a Date Field in Twig

Here are the four easiest ways I’ve found to show dates via Twig inside of a node template.

They all result in the same output.

Use the field’s formatter settings; include wrappers

This is the only example that includes wrappers. The rest output just the date.


Use the field’s formatter settings

This will use the format defined in Content type » Manage Displays » Your View Mode.


Use Twig date filter + a defined Drupal date format

I have defined, via the Drupal UI, a date format. Here’s the config for it:

uuid: 1a50c79f-96df-45de-9a21-32e0d8327806
langcode: en
status: true
dependencies: { }
id: short_mdyyyy
label: 'Short - m/d/yyyy'
locked: false
pattern: n/j/Y


Use Twig date filter

Tagged with: , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *