getYearsUntil()function

getYearsUntil(target: PossibleDate, current?: PossibleDate, caller: AnyCaller = getYearsUntil): number
ParamType
targetPossibleDate
Date to count up to. required
currentPossibleDate
Date to count from (defaults to now).
callerAnyCaller
Function to attribute a thrown error to (defaults to getYearsUntil itself). Defaults to getYearsUntil
Return
number
Number of calendar years from current to target (negative if target is in the past).
Throws
RequiredError
If target or current cannot be converted to a valid date.

Count the calendar years until a date.

  • e.g. from December 31st to January 1st is 1 year, even though it's only 1 day.

Examples

getYearsUntil(target) // 2