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
getTimeDifffunction.
getRelativeYear
Returns the number of full years between 2 inputs.
Function Signature
const getRelativeYear: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full years between the two dates.
Example Usage
getRelativeMonth
Returns the number of full months between 2 inputs.
Function Signature
const getRelativeMonth: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full months between the two dates.
Example Usage
getRelativeWeek
Returns the number of full weeks between 2 inputs.
Function Signature
const getRelativeWeek: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full weeks between the two dates.
Example Usage
getRelativeDay
Returns the number of full days between 2 inputs.
Function Signature
const getRelativeDay: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full days between the two dates.
Example Usage
getRelativeHour
Returns the number of full hours between 2 inputs.
Function Signature
const getRelativeHour: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full hours between the two dates.
Example Usage
getRelativeMinute
Returns the number of full minutes between 2 inputs.
Function Signature
const getRelativeMinute: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full minutes between the two dates.
Example Usage
getRelativeSecond
Returns the number of full seconds between 2 inputs.
Function Signature
const getRelativeSecond: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full seconds between the two dates.
Example Usage
getRelativeMillisecond
Returns the number of full milliseconds between 2 inputs.
Function Signature
const getRelativeMillisecond: (date1: Maybe<DateArgs>, date2: Maybe<DateArgs>) => numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
The number of full milliseconds between the two dates.
Example Usage
Last updated: Sun, Jun 28, 2026 04:50:21AM (UTC)
