# wrRelativeTime

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

Source: https://ngwr.dev/reference/pipes/wr-relative-time  
Kind: Pipe  
Added in v16.9  
Optional

## Installation

Import the class. This entry point has no stylesheet.

```typescript
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.

```angular-html
{{ 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"        -->
```

## 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.

## Playground

```angular-html
{{ value | wrRelativeTime: { numeric: 'auto', style: 'long' } }}
```

```angular-ts
import { Component } from '@angular/core';

import { WrRelativeTime } from 'ngwr/pipes';

/**
 * Playground
 */
@Component({
  selector: 'wrrelativetime-playground-example',
  templateUrl: './wrrelativetime-playground-example.html',
  imports: [WrRelativeTime],
})
export class WrrelativetimePlaygroundExample {
  // Stubs. The page owned these values; the snippet shows the markup
  // that reads them, not where they come from.
  protected value: any = null;
}
```

## Live text

The pipe does not update by itself: it is pure, so the text stands until its value or options change. [Date Stamp](https://ngwr.dev/reference/components/date-stamp) with `relative` keeps it current on a timer.

```angular-html
<!-- 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.

```angular-ts
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
```

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `wrRelativeTime` | How 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` | `-` |
| `wrFormatRelativeTime` | The 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.now` | The instant the value is measured from. | `Date \| number` | `the current time` |
| `options.numeric` | `auto` lets the language say "yesterday", "tomorrow" and "now". `always` keeps the number. | `'auto' \| 'always'` | `'auto'` |
| `options.style` | How much of the unit is written, as `Intl.RelativeTimeFormat` reads it. | `'long' \| 'short' \| 'narrow'` | `'long'` |
| `options.epochUnit, zonelessIn, timeZone` | How the value is read, as the last argument of `wrDate` says it. | `WrParseDateOptions` | ```withDates()` in the pipe`` |

## See also

- [Date Stamp](https://ngwr.dev/reference/components/date-stamp) — A date over a time, for a table cell.
- [wrDate](https://ngwr.dev/reference/pipes/wr-date) — Format a date with a named preset or a token string.
- [wrDuration](https://ngwr.dev/reference/pipes/wr-duration) — Show a span of milliseconds as clock digits, as units or as a timer.
