ChronosChronos

Get Relative Time

Get full relative time between 2 dates in specified unit.

Note

  • Calculation order is date2 - date1.
  • These functions return integer values (whole numbers).
  • For exact values (integer or float), use the getTimeDiff function.

getRelativeYear

Returns the number of full years between 2 inputs.

Function Signature

const getRelativeYear: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full years between the two dates.

Example Usage

playground.ts

getRelativeMonth

Returns the number of full months between 2 inputs.

Function Signature

const getRelativeMonth: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full months between the two dates.

Example Usage

playground.ts

getRelativeWeek

Returns the number of full weeks between 2 inputs.

Function Signature

const getRelativeWeek: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full weeks between the two dates.

Example Usage

playground.ts

getRelativeDay

Returns the number of full days between 2 inputs.

Function Signature

const getRelativeDay: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full days between the two dates.

Example Usage

playground.ts

getRelativeHour

Returns the number of full hours between 2 inputs.

Function Signature

const getRelativeHour: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full hours between the two dates.

Example Usage

playground.ts

getRelativeMinute

Returns the number of full minutes between 2 inputs.

Function Signature

const getRelativeMinute: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full minutes between the two dates.

Example Usage

playground.ts

getRelativeSecond

Returns the number of full seconds between 2 inputs.

Function Signature

const getRelativeSecond: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full seconds between the two dates.

Example Usage

playground.ts

getRelativeMillisecond

Returns the number of full milliseconds between 2 inputs.

Function Signature

const getRelativeMillisecond: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

Returns

The number of full milliseconds between the two dates.

Example Usage

playground.ts

Last updated: Sun, Jun 28, 2026 04:50:21AM (UTC)

On this page