Skip to main content

filters/date

Displays a date in a particular format.

{{ post.published_at|date }}

Arguments

Name Type Default Description
format str '%B %-d, %Y %H:%M' The format used to display the date.
isoformat bool False Whether to use the ISO 8601 format. If True then format is ignored.

Description

The date filter enables you to output a date in a desired format. Use the format argument to specificy the format to be used. See this formatting guide for more information. Alternatively set the isoformat to True and the ISO 8601 format will be used for outputting a machine-readable date. The date filter can also be used with the now date in the global context, handy for displaying a copyright year for example.

Examples

Default Arguments

Input

{{ post.published_at|date }}

Output

June 3, 2015 15:30

Non-Default Arguments

Input

{{ post.published_at|date(format='%B %-d at %-I:%M %p') }}

Output

June 3 at 3:30 PM

ISO 8601 Format

Input

{{ post.published_at|date(isoformat=True) }}

Output

2015-06-03T15:30:00+01:00

A typical use is to provide a machine-readable version of a date for the HTML time element.

<time datetime="{{ post.published_at|date(isoformat=True) }}">{{ post.published_at|date }}</time>

The Date Now

Input

{{ now|date(format='%Y') }}

Output

2015