Go to page content

date

Format a date and time.

Formats a date or datetime according to the format specified in the argument.

The date should be a tuple {Y,M,D} and the datetime should be a tuple {{Y,M,D},{H,I,S}}.  Dates and datetimes are always assumed to be in local time.

An example:

{{ mydate|date:"Y-m-d" }}

When mydate is {2009,6,1} this gives “2009-06-01” as output.

See also the timesince filter to display a human readable relative time like "10 hours ago".

Date uses the same format as PHP's date function with some extensions and some omissions.

All supported formatting characters are listed below:

CharacterDescriptionExample output
a“a.m.” or “p.m.” (note that this follows Associated Press style and adds periods)“a.m.”
AUppercase “AM” or “PM”“AM”
bMonth, textual, in three lowercase characters.“jan”
cISO-8601 date format“2004-02-12T15:19:21+00:00”
dDay of the month in two digits with leading zeros, i.e. “01” to “31”“01”
DDay of the week, textual, three letters of which the first one uppercase.“Mon”, “Fri”
fIf minutes is zero then show only the hour, otherwise the hour and the minutes. Hours are shown using the “g” format character.“2”, “3:01”
FMonth, textual, full english name with first character in uppercase.“January”
g12 Hour format without leading zero, i.e. “1” to “12”.“1”
G24 Hour format without leading zero, i.e. “0” to “23”“0”, “15”
h12 Hour format with leading zero, i.e. “01” to “12”“01”
H24 Hour format with leading zero, i.e. “00” to “23”“00”, “15”
iMinutes with leading zero, i.e. “00” to “59”“00”, “46”
jDay of the month without leading zeros, i.e. “1” to “31”“1”, “28”
l(lowercase L) Day of the week, textual, full english name with first character in uppercase.“Monday”, “Friday”
LBoolean for whether the year is a leap year.  Returns the string “True” or “False”."True", "False"
mMonth with leading zeros, i.e. “01” to “12”“01”, “12”
MMonth, textual, in three characters, first character in uppercase.“Jan”
nMonth without leading zeros, i.e. “1” to “12”“1”, “12”
NMonth abbreviation in Associated Press style. March, April, June and July are shown in full. September as “Sept.” and all other months as three letter abbreviations with a full stop appended.“Jan.”, “June”, “Sept.”, “Dec.”
ODifference to Greenwich Mean Time (GMT).“+0200”
PTime in 12 hour format with minutes and “a.m.” or “p.m.” appended. Minutes are left off if they are zero, and the strings “midnight” or “noon” if appropriate.“1 a.m.”, “noon”, “1:30 a.m.”, “12:30 p.m.”
rRFC 2822 formatted date.“Thu, 21 Dec 2000 16:01:07 +0200”
SEnglish ordinal suffix for the day of the month, 2 characters; i.e. “st”, “nd”, “rd” or “th”“st”, “nd”
tNumber of days in the given month, i.e. “28” to “31”“30”
USeconds since the Unix epoch of January 1, 00:00:00 GMT.1254911050
wDay of the week, numeric.  0 For sunday to 6 for saturday.“0”, “6”
WISO-8601 week number of the year, starting on mondays.“22”
yYear in two digits.“01”, “99”
YYear in four digits.“1999”, “2010”
zDay of the year, i.e. 1 to 366.“361”

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.