timesince
Show a readable version of a date/time difference.
Translates the difference between two dates into a simple readable string like “2 minutes, 10 seconds ago”.
Optionally takes an argument with the date to compare against, which is by default the current local date/time.
Example:
{{ my_date|timesince }}
When “my_date” is {{2008,12,10},{15,30,0}} and the current date/time is {{2009,11,4},{13,50,0}} then this
outputs “10 months, 24 days ago”. When the time value is in the future then it outputs a string like “in X minutes”.
This function does not take daylight saving changes into account.
Extra arguments
The timesince filter can take several extra arguments, in the order of arguments:
- Base date to use. Useful to show the difference between two dates, defaults to
now - Text to use for the relative time designations. The default uses translated sentence patterns and direction-specific plural units. Pass
"default"to select this behavior explicitly, or an empty string for a duration without direction. Custom comma-separated indicators such as"ago,now,in"are also supported. - Format for the printout. Now two options
1and2, for the number of components shown. For example2will show 2 minutes, 10 seconds ago where1will show 2 minutes ago
Example
Show the time between creation and modification of a resource:
{{ id.created|timesince:id.modified:"":1 }}
The default translations distinguish past, future, and standalone durations using
gettext msgctxt values relative time: past, relative time: future, and
relative time: duration. Each unit selects its own plural form. The translated
patterns {first}, {second}, {duration} ago, and in {duration} control the
separator, order, and placement of the direction. For example, two components
produce “2 minutes, 10 seconds ago”, with the direction shown once.
Custom indicators are applied literally to standalone duration forms; use the default behavior when the unit's grammatical case depends on the direction.
The example above might display something like:
10 days