PipeAdded in v16.9Optional

wrRelativeTime

Say how far a date is from now in the app locale: "5 minutes ago", "tomorrow".

Installation

Import the class. This entry point has no stylesheet.

import { Component } from '@angular/core';
import { WrRelativeTime, wrFormatRelativeTime } from 'ngwr/pipes';

@Component({ imports: [WrRelativeTime] })
export class MyComponent {}

Basic usage

The pipe writes through Intl.RelativeTimeFormat in LOCALE_ID and reads a value as wrDate does.

{{ comment.createdAt | wrRelativeTime }}                       <!-- "5 minutes ago" -->
{{ task.dueAt | wrRelativeTime }}                              <!-- "in 3 hours"    -->
{{ order.paidAt | wrRelativeTime: { numeric: 'always' } }}     <!-- "1 day ago"     -->
{{ comment.createdAt | wrRelativeTime: { style: 'narrow' } }}  <!-- "5m ago"        -->
Five minutes back5 minutes ago
Three hours aheadin 3 hours
A day backyesterday
numeric: 'always'1 day ago
style: 'narrow'5m ago

Units

The unit follows the distance. The count is cut, not rounded: 119 seconds is one minute. A year is 365 days and a month a twelfth of it. A date-only string is compared with today as a day.

DistanceUnit
Under a minuteseconds
Under an hourminutes
Under a dayhours
Under a weekdays
Under a monthweeks
Under a yearmonths
A year or moreyears

Playground

5 minutes ago

{{ value | wrRelativeTime: { numeric: 'auto', style: 'long' } }}

Customize

Distance
In the future
Numeric
Style

Live text

The pipe does not update by itself: it is pure, so the text stands until its value or options change. Date Stamp with relative keeps it current on a timer.

<!-- Stays current: re-renders on a timer -->
<wr-date-stamp [value]="comment.createdAt" relative />

<!-- Or move the reference instant yourself -->
{{ comment.createdAt | wrRelativeTime: { now: clock() } }}

In TypeScript

wrFormatRelativeTime gives the same text for a string built in code, in the locale you pass.

import { wrFormatRelativeTime } from 'ngwr/pipes';

const now = new Date('2026-11-12T12:00:00Z');

wrFormatRelativeTime('2026-11-12T11:55:00Z', 'en-GB', { now }); // "5 minutes ago"
wrFormatRelativeTime('2026-11-11T12:00:00Z', 'en-GB', { now }); // "yesterday"
wrFormatRelativeTime('2026-11-12T15:00:00Z', 'ru', { now });    // "через 3 часа"
wrFormatRelativeTime(row.createdAt, 'en-GB');                   // from the current time
LocaleFive minutes backA day backThree hours ahead
en-GB5 minutes agoyesterdayin 3 hours
devor 5 Minutengesternin 3 Stunden
eshace 5 minutosayerdentro de 3 horas
ru5 минут назадвчерачерез 3 часа
ja5 分前昨日3 時間後

API

NameDescriptionTypeDefault
wrRelativeTimeHow far the value is from now, through Intl.RelativeTimeFormat in LOCALE_ID. Reads a Date, an epoch number or a string, as wrDate does, under the epochUnit and zonelessIn of withDates(). null, undefined, a blank string and a value that is not a date give an empty string.(value: Date | string | number | null | undefined, options?: WrRelativeTimeOptions) => string-
wrFormatRelativeTimeThe pipe as a function, in the locale given. It reads no app setting: a number is milliseconds.(value: Date | string | number | null | undefined, locale: string, options?: WrRelativeTimeOptions) => string-
options.nowThe instant the value is measured from.Date | numberthe current time
options.numericauto lets the language say "yesterday", "tomorrow" and "now". always keeps the number.'auto' | 'always''auto'
options.styleHow much of the unit is written, as Intl.RelativeTimeFormat reads it.'long' | 'short' | 'narrow''long'
options.epochUnit, zonelessIn, timeZoneHow the value is read, as the last argument of wrDate says it.WrParseDateOptions`withDates()` in the pipe

See also