Using date and time in templates
Formatting and comparison on dates and times
Last updated
Formatting and comparison on dates and times
Last updated
datefmt
Format a date/time to output a specific format.
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 |
---|---|
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
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
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.
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
Show something if the date is today or in the future
The now
is the current date and time
Example
Output
{{ timestamp|datefmt('long') }}
January 1, 2024
{{ timestamp|datefmt('Y') }}
2024
{{ timevalue|timefmt('short') }}
3:23 PM
{{ timestamp|timefmt('a') }}
PM