Skip to content Skip to footer navigation

Relative Modifier

Returns a date difference in a nice, human readable, string format. This modifier will add a phrase after the difference value relative to the current date and the passed in date.

You can turn off the extra words "ago", "until", and so on by passing true as a parameter

The string will be localized into your current site locale.

# Assuming the current date is June 19, 2014.
past_date: June 19 2012
future_date: June 19 2015
{{ past_date | relative }}
{{ past_date | relative(true) }}
{{ future_date | relative }}
{{ future_date | relative(true) }}
{{ Statamic::modify($past_date)->relative() }}
{{ Statamic::modify($past_date)->relative(true) }}
{{ Statamic::modify($future_date)->relative() }}
{{ Statamic::modify($future_date)->relative(true) }}
2 years ago
2 years
1 year from now
1 year
Warning!

Date modifiers preserve the date value's timezone by default. Dated entries use UTC. Enable localize_dates_in_modifiers in config/statamic/system.php to convert dates to your display timezone before applying modifiers.

Please refer to our Timezones guide for more information.

A troll pointing a teaching stick