time_ago

The time_ago filter formats a date as a more friendly, relative value. For example, "35 minutes ago", "4 hours ago" or "3 days ago".

{{ post.publishedOnTimestamp|time_ago }}

By default the time_ago filter will not show the date but will always show a relative value of how long ago the date was. You can change that by passing options as described below.

Arguments

The time_ago filter has the following signature.

time_ago(options)

Argument Description
options

An optional array of options to change the default behavior of of the time_ago filter.

Example:

{{ post.publishedOnTimestamp|time_ago({'showDateAfter': 'month', 'format': 'M d, Y'}) }}

The options are listed below.

Option Description
showDateAfter

The date unit to stop showing a relative value after. By default the filter will always show a relative value.

For example, if week is passed then if the date difference is more than one week then the date format will be used. If the difference is less than one week then the relative value will be used.

Accepted values:

  • second
  • minute
  • hour
  • day
  • week
  • month
  • year
  • decade

Example:

{{ post.publishedOnTimestamp|time_ago({'showDateAfter': 'month'}) }}

format

The date format to use to display the date is the showDateAfter option is set.

The default date format is M d, Y g:i a

See the date formats page for allowed date formats.

Example:

{{ post.publishedOnTimestamp|time_ago({'showDateAfter': 'month', 'format': 'M d, Y'}) }}

< Back to the list of filters