ActionView::Helpers::DateHelper

distance_of_time_in_words

API docs (Rails 8.1.4.1) ↗
def distance_of_time_in_words(from_time, to_time = 0, options = {})

Description

Returns the difference between two times as a string such as "about 2 hours".

Arguments

Changing a value updates the ERB and HTML.

Time.zone.local(2026, 11, 9, 9, 0, 0)
Turns the difference from the to_time argument into a string such as "about 2 hours", built from the datetime.distance_in_words translations. Besides a Time, Date or DateTime, accepts a number (seconds since 1970) or a string that to_time can convert. nil and the like raise ArgumentError. A time later than to_time gives the same string.
= 0
The time to compare with the from_time argument. Defaults to 0 (the Unix epoch, January 1, 1970).
options= {}
true splits a difference shorter than a minute and a half more finely: under 40 seconds, a string in seconds (such as half a minute); under 60 seconds, less than a minute; otherwise 1 minute. By default, it is less than a minute under 30 seconds and 1 minute otherwise.
Uses this locale's translations instead of the current one.
:"datetime.custom"
Looks up the translations (x_minutes, etc.) under this scope instead of datetime.distance_in_words. This page's example scope is not in this site's translations, so it returns a "translation missing" string.
Other options are ignored. They do not become HTML attributes either.

ERB

Changes from the previous output: Added Removed Changed


          

HTML