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

formatDistanceToNow

import { formatDistanceToNow } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// If today is 1 January 2015, what is the distance to 2 July 2014?
const result = formatDistanceToNow(
  new Date(2014, 6, 2)
)
//=> '6 months'
@example
// If now is 1 January 2015 00:00:00,
// what is the distance to 1 January 2015 00:00:15, including seconds?
const result = formatDistanceToNow(
  new Date(2015, 0, 1, 0, 0, 15),
  {includeSeconds: true}
)
//=> 'less than 20 seconds'
@example
// If today is 1 January 2015,
// what is the distance to 1 January 2016, with a suffix?
const result = formatDistanceToNow(
  new Date(2016, 0, 1),
  {addSuffix: true}
)
//=> 'in about 1 year'
@example
// If today is 1 January 2015,
// what is the distance to 1 August 2016 in Esperanto?
const eoLocale = require('date-fns/locale/eo')
const result = formatDistanceToNow(
  new Date(2016, 7, 1),
  {locale: eoLocale}
)
//=> 'pli ol 1 jaro'
function formatDistanceToNow<DateType extends Date>(date: DateType | number | string, options?: FormatDistanceToNowOptions): string;
§
formatDistanceToNow<DateType extends Date>(date: DateType | number | string, options?: FormatDistanceToNowOptions): string
[src]

§Type Parameters

§
DateType extends Date
[src]

§Parameters

§
date: DateType | number | string
[src]
  • The given date
§
  • The object with options

§Return Type

§
string
[src]

The distance in words