Using date and time in templates

Formatting and comparison on dates and times

Template utilities

datefmt

Format a date/time to output a specific format.

Example

Output

{{ timestamp|datefmt('long') }}

January 1, 2024

{{ timestamp|datefmt('Y') }}

2024

More examples of the formats available can be found here: http://babel.pocoo.org/en/latest/dates.html#date-fields

timefmt

Format a time to output a specific format.

Example
Output

{{ timevalue|timefmt('short') }}

3:23 PM

{{ timestamp|timefmt('a') }}

PM

More examples of the formats available can be found here: https://babel.pocoo.org/en/latest/dates.html#time-fields

now

This is quick access to the current date and time

<p>The current date is: {{ now|datefmt('MMMM d') }}</p>

Output

day_name

Output the name of the day using the "0 index" of the day of the week.

Output

to_date

Utility to parse a date from a string

Optionally, you can also pass a format to the parsing

to_datetime

Utility to parse a date and time from a string

to_time

Utility to parse a time from a string

Optionally, you can also pass a format to the parsing

from_timestamp

Can be used to convert unix timestamps (i.e. an integer) into date/time to be used by other functions.

Output

Hide content based on date

Using the advanced jinja2 templating to hide a piece of content depending on the date. This can be used to have something show up before/after/during a date range.

This uses our to_date jinja filter. Take note of the greater than and less than operators.

The to_date is parsed as the first minute and hour of the day so using greater and less than operators is the best way to write the conditionals.

Today, future, or past comparisons

is_today

Show something if the date is today

is_future

Show something if the date is in the future

is_past

Show something if the date is in the past

Combining the above filters

Show something if the date is today or in the future

Using now to compare to the current day and time

The now is the current date and time

Starting on a date

Up to a date

Date range

Last updated

Was this helpful?