django :: date filter cheat sheet

I don’t seem able to memorize the list of format characters for the date filter, maybe because the documentation lists them in alphabetical order. I’ve created the cheat sheet below with an attempt at semantic grouping…

Time seconds s Seconds, 2 digits (with leading zeros).
minutes i Minutes (with leading zeros).
hours
(24 hr clock)
G Hour, 24-hour format without leading zeros.
H Hour, 24-hour format with leading zeros.
hours
(12 hr clock)
g Hour, 12-hour format without leading zeros.
h Hour, 12-hour format with leading zeros.
a a.m. or p.m.
A A.M. or P.M.
Date year y Year, 2 digits.
Y Year, 4 digits.
z Day of the year (0 – 365).
week W ISO-8601 week number.
w Day number of the week (0=Sunday, 6=Saturday).
month n Month number
m Month number, 2 digits (leading zeros)
b Month name, lower case, 3 characters.
M Month name, 3 characters.
F Month name
day j Day of the month
d Day of the month, 2 digits (leading zeros).
D Day name, 3 characters.
l Day name
z Day of the year (0 – 365)
w Day number of the week (0=Sunday, 6=Saturday).
misc. metainfo t Number of days in the given month.
L Leap year? (bool).
special formats r RFC 2822 formatted date..
U Seconds since the Unix Epoch (1970-01-01 00:00:00).
z Day of the year (0 – 365).
time zone O Difference to Greenwich time in hours.
Z Time zone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive..
T Time zone of this machine. (‘EST’, ‘MDT’).
English only S English ordinal suffix for day of the month (1st, 2nd)
P Time, in 12-hour hours, minutes and ‘a.m.’/’p.m.’, with minutes left off if they’re zero and the special-case strings ‘midnight’ and ‘noon’ if appropriate. Proprietary extension.
f Time, in 12-hour hours and minutes, with minutes left off if they’re zero. (Proprietary extension.)
N Month abbreviation in Associated Press Style (proprietary extension).
This entry was posted in django. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *