date Filter

Date and Time Most Useful

Argument: format (Optional) – a format string or a predefined format.

Documentation

Used to format the date and time of a datetime or date object.

The format argument can be constructed using format strings or one of the following predefined formats:

  1. DATE_FORMAT
  2. DATETIME_FORMAT
  3. SHORT_DATE_FORMAT
  4. SHORT_DATETIME_FORMAT

Variable

moon_landing = datetime.datetime(year=1969, month=7, day=21,
        hour=2, minute=56, second=15,
        tzinfo=datetime.timezone.utc)

Sample Formats

  • {{ moon_landing }} – July 21, 1969, 2:56 a.m.
  • {{ moon_landing|date }} – July 21, 1969
  • {{ moon_landing|date:'l, F j, Y' }} – Monday, July 21, 1969
  • {{ moon_landing|date:"DATE_FORMAT" }} – July 21, 1969
  • {{ moon_landing|date:"DATETIME_FORMAT" }} – July 21, 1969, 2:56 a.m.
  • {{ moon_landing|date:"SHORT_DATE_FORMAT" }} – 07/21/1969
  • {{ moon_landing|date:"SHORT_DATETIME_FORMAT" }} – 07/21/1969 2:56 a.m.

Note that the predefined formats are based on the current locale.


Did we get something wrong? Is there a use case for the date filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on April 14, 2020, 9:27 a.m. EST