[Django]-Django "naturalday" template filter: fall back to formatted date?

5👍

Pass the format after the :, like in date filter:

Date: {{ result_date|naturalday:"F d" }}
  • F is a textual representation of month, e.g. July.
  • d is a day of the month, 2 digits with leading zeros, e.g. 25.

Hope that helps.

👤alecxe

2👍

You should check the example:

Examples (when ‘today’ is 17 Feb 2007):

  • 16 Feb 2007 becomes yesterday.
  • 17 Feb 2007 becomes today.
  • 18 Feb 2007 becomes tomorrow.
  • Any other day is formatted according to given argument or the DATE_FORMAT setting if no argument is given.

Then about DATE_FORMAT:

Default: ‘N j, Y’ (e.g. Feb. 4, 2003)

The default formatting to use for displaying date fields in any part
of the system. Note that if USE_L10N is set to True, then the
locale-dictated format has higher precedence and will be applied
instead. See allowed date format strings.

So it will fall back to Feb. 17, 2007 if no format string argument is provided and DATE_FORMAT is not specified in settings.py.

The normal fall back format string is provided in alecxe’s answer.

Leave a comment