getMonthsAgo()function

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

Count the calendar months since a date.

  • e.g. from March 31st to April 1st is 1 month, even though it's only 1 day.

Examples

getMonthsAgo(target) // 14