getDuration()function

getDuration(from?: PossibleDate, to?: PossibleDate, caller: AnyCaller = getDuration): DurationData
ParamType
fromPossibleDate
Date the duration is measured from (defaults to now).
toPossibleDate
Date the duration is measured to (defaults to now).
callerAnyCaller
Function to attribute a thrown error to (defaults to getDuration itself). Defaults to getDuration
Return
DurationData
DurationData object breaking the span down into years, months, weeks, days, hours, minutes, seconds, and milliseconds.
Throws
RequiredError
If from or to cannot be converted to a valid date.

Count the various time units between two dates and return a Duration format.

Examples

getDuration("2025-01-01", "2025-01-02") // { years: 0, months: 0, weeks: 0, days: 1, ... }