Method Deck / dates

Age in years, months, and days

Computes exact calendar age (years, months, days) between a birth date and an as-of date.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Parse birth_date and as_of_date as proleptic Gregorian civil dates; require as_of_date on or after birth_date (checked via day-number, Hinnant days_from_civil, cited above).
  2. years = as_of.year - birth.year; months = as_of.month - birth.month; days = as_of.day - birth.day.
  3. If days is negative: subtract 1 from months, and walk back one calendar month at a time from as_of_date's month, adding that month's day count to days, repeating until days is no longer negative (this handles the rare case where the birth day-of-month exceeds the days in the immediately preceding month, e.g. a day-31 birth date compared against an early day in a short month).
  4. If months is still negative after that, subtract 1 from years and add 12 to months.
  5. The result is the completed years, months, and days of age as of as_of_date.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"birth_date":"1990-06-15","as_of_date":"2026-09-30"}36 years, 3 months, 15 days
test vector: single-month borrow{"birth_date":"1995-11-20","as_of_date":"2026-03-05"}30 years, 3 months, 13 days
test vector: same-day age is exact years{"birth_date":"2000-02-29","as_of_date":"2024-02-29"}24 years, 0 months, 0 days

Published card