Using date and time in templates
Formatting and comparison on dates and times
Template utilities
datefmt
datefmtFormat 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
timefmtFormat a time to output a specific format.
{{ 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
nowThis is quick access to the current date and time
<p>The current date is: {{ now|datefmt('MMMM d') }}</p>Output
day_name
day_nameOutput the name of the day using the "0 index" of the day of the week.
Output
to_date
to_dateUtility to parse a date from a string
Optionally, you can also pass a format to the parsing
to_datetime
to_datetimeUtility to parse a date and time from a string
to_time
to_timeUtility to parse a time from a string
Optionally, you can also pass a format to the parsing
from_timestamp
from_timestampCan 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
is_todayShow something if the date is today
is_future
is_futureShow something if the date is in the future
is_past
is_pastShow 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?