ActionView::Helpers::DateHelper

relative_time_in_words

API docs (Rails 8.1.4.1) ↗
def relative_time_in_words(from_time, options = {})

Description

Converts the difference from the current time to the same string as distance_of_time_in_words, and returns it inserted into %{time} of the datetime.relative.past translation (in the past) or datetime.relative.future (in the future).

Arguments

Changing a value updates the ERB and HTML.

A Time, DateTime or Date, or a string that can be read as a time ("2026-11-20"). A number (of seconds) or nil raises ArgumentError. Uses the future translation if it is later than the current time (Time.now), and past otherwise. Rails ships only English translations, and rails-i18n has no Japanese one yet, so in Japanese it returns a "translation missing" string. This site does not provide a Japanese translation either.
options= {}
true splits differences under a minute into steps of seconds (as distance_of_time_in_words does).
Uses this locale's translations instead of the current one, for both the difference and the past and future translations. There is no Japanese translation, so this page passes :en at first.
:"datetime.custom"
The scope to look up the past and future translations in: the past and future keys under it. It is not passed to distance_of_time_in_words, so the translation of the difference does not change. This page's example scope is not in this site's translations, so it returns a "translation missing" string.
Other options are passed to distance_of_time_in_words as is. They do not become HTML attributes.

ERB

Changes from the previous output: Added Removed Changed


          

HTML