Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

intlFormatDistance

import { intlFormatDistance } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// What is the distance between the dates when the fist date is after the second?
intlFormatDistance(
  new Date(1986, 3, 4, 11, 30, 0),
  new Date(1986, 3, 4, 10, 30, 0)
)
//=> 'in 1 hour'

// What is the distance between the dates when the fist date is before the second?
intlFormatDistance(
  new Date(1986, 3, 4, 10, 30, 0),
  new Date(1986, 3, 4, 11, 30, 0)
)
//=> '1 hour ago'
@example
// Use the unit option to force the function to output the result in quarters. Without setting it, the example would return "next year"
intlFormatDistance(
  new Date(1987, 6, 4, 10, 30, 0),
  new Date(1986, 3, 4, 10, 30, 0),
  { unit: 'quarter' }
)
//=> 'in 5 quarters'
@example
// Use the locale option to get the result in Spanish. Without setting it, the example would return "in 1 hour".
intlFormatDistance(
  new Date(1986, 3, 4, 11, 30, 0),
  new Date(1986, 3, 4, 10, 30, 0),
  { locale: 'es' }
)
//=> 'dentro de 1 hora'
@example
// Use the numeric option to force the function to use numeric values. Without setting it, the example would return "tomorrow".
intlFormatDistance(
  new Date(1986, 3, 5, 11, 30, 0),
  new Date(1986, 3, 4, 11, 30, 0),
  { numeric: 'always' }
)
//=> 'in 1 day'
@example
// Use the style option to force the function to use short values. Without setting it, the example would return "in 2 years".
intlFormatDistance(
  new Date(1988, 3, 4, 11, 30, 0),
  new Date(1986, 3, 4, 11, 30, 0),
  { style: 'short' }
)
//=> 'in 2 yr'
function intlFormatDistance<DateType extends Date>(
date: DateType | number | string,
baseDate: DateType | number | string,
): string;
§
intlFormatDistance<DateType extends Date>(date: DateType | number | string, baseDate: DateType | number | string, options?: IntlFormatDistanceOptions): string
[src]

§Type Parameters

§
DateType extends Date
[src]

§Parameters

§
date: DateType | number | string
[src]
  • The date
§
baseDate: DateType | number | string
[src]
  • The date to compare with.
§

§Return Type

§
string
[src]

The distance in words according to language-sensitive relative time formatting.