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

{{ content.field_blog_date }}
1
{{ content.field_blog_date }}
This is the only example that includes wrappers. The rest output just the date.

Use the field’s formatter settings

{{ content.field_blog_date.0 }}
1
{{ content.field_blog_date.0 }}
This will use the format defined in Content type » Manage Displays » Your View Mode.

Use Twig date filter + a defined Drupal date format

{{ node.field_blog_date.value|date('U')|format_date('short_mdyyyy') }}
1
{{ node.field_blog_date.value|date('U')|format_date('short_mdyyyy') }}
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

{{ node.field_blog_date.value|date('n/j/Y') }}
1
{{ node.field_blog_date.value|date('n/j/Y') }}