timesince Filter

Date and Time Most Useful

Argument: to_date (Optional) – The date to compare to.

Documentation

Outputs the amount of time between the value and the to_date argument, which defaults to the current time.

Variables

launch_date = datetime.datetime(year=1969, month=7, day=16,
        hour=13, minute=32, second=0,
        tzinfo=datetime.timezone.utc)

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

Template

{{ moon_landing|timesince }}<br>
{{ launch_date|timesince:moon_landing }}

Result

50 years, 8 months<br>
4 days, 13 hours

The output in the browser will look like this:

50 years, 8 months
4 days, 13 hours

  • The first time period is the amount of time that has passed since the moon landing (based on the time this documentation is being written).
  • The second time period is the time between the rocket launch and the moment Neil Armstrong stepped on the moon.

Commentary

This is commonly used to output how much time has passed since an article was written (e.g., Posted 1 year, 2 months ago).


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

Send Feedback

Official Documentation
This page last updated on Oct. 30, 2022, 1:21 p.m. EST