jinja2 datetime format

{{ date_of_something.strftime('%Y-%m-%d') }}

Here is what the above code is Doing:
1. We’re importing the datetime module.
2. We’re creating a variable called date_of_something and assigning it to a datetime object.
3. We’re using the strftime method to format the date.
4. We’re printing the formatted date.

The strftime method takes one parameter, format, to specify the format of the returned string.

The format parameter uses codes like %Y, %m, and %d to indicate which part of the datetime to format.

Here’s a list of the codes:

Code Meaning
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale’s equivalent of either AM or PM.
%A Weekday as locale’s full name.
%a Weekday as locale’s abbreviated name.
%B Month as locale’s full name.
%b Month as locale’s abbreviated name.
%c Locale’s appropriate date and time representation.
%j Day of the year as a decimal number [001,366].
%p Locale’s equivalent of either AM or PM.
%U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
%W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.
%w Weekday as a decimal number [0(Sunday),6].
%x Locale’s appropriate date representation.
%X Locale’s appropriate time representation.
%Z Time zone name (no characters if no time zone exists).
%% A literal ‘%’ character.