Calculate age in years, months, and days
Calculating age seems like simple subtraction. But if you were born on January 31st, and today is March 1st, are you exactly 1 month old? How many days are left over?
Unlike seconds or minutes, a "month" is not a fixed unit of time. It can be 28, 29, 30, or 31 days long. Therefore, simply subtracting two Unix timestamps gives you an absolute number of milliseconds, which cannot be perfectly divided into months.
To get an exact "Years, Months, Days" breakdown, developers have to use calendar-aware math instead of absolute timestamps:
Step 3 in the algorithm above is where most custom scripts fail. The "number of days in the previous month" changes if that month was February during a leap year.
A leap year occurs if the year is divisible by 4, but not by 100—unless it is also divisible by 400. This tool uses robust time libraries (like date-fns) that handle these Gregorian calendar quirks perfectly, rather than relying on flawed manual JavaScript date math.
Why can't you calculate an exact age (in months) by simply subtracting the birth timestamp from the current timestamp?