O3 Framework / formatDurationBetween
formatDurationBetween(
startDate,endDate,options?):null|string
Defined in: packages/framework/esm-utils/src/dates/date-util.ts:707
Calculates the duration between two dates and formats it as a locale-aware string. Uses the same unit-selection logic as duration and delegates formatting to formatDuration.
ConfigType
The start date. If null, returns null.
ConfigType = ...
Optional. Defaults to now.
A unit string for single-unit output, or a DurationOptionsWithFormat object.
The formatOptions field is passed to Intl.DurationFormat (defaults to short style).
DurationUnit |
DurationOptionsWithFormat |
null | string
A formatted duration string, or null if either date is null or unparseable.
formatDurationBetween('2022-01-01', '2024-07-30') // => '2 yrs'
// Multi-unit with long-form formatting
formatDurationBetween('2022-01-01', '2024-07-30', {
largestUnit: 'year',
smallestUnit: 'day',
formatOptions: { style: 'long' },
}) // => '2 years, 6 months, 29 days'