0

I just stumbled on an interesting problem when trying to calculate birthday from age. Basically the idea is to substract a number of years, months and days from the current date. However depending on the order of subtraction eg smaller to larger units or vice versa the result is different.

For example we need to substract 55 years 3 months and 14 days from 2021-01-13

If I subtract the years first the result will be 1965-09-29

If I subtract the days first the result will be 1965-09-30

It all comes from the difference between the number of days in a month. Now I'm wondering which is the generally accepted order.

Dobromir Velev
  • 530
  • 2
  • 15
  • You can use both orders. It is like calculating a subtraction on paper: you can uses the two methods, just remember the "carry" or "borrower" flags in the correct way. – Giacomo Catenazzi Jan 13 '21 at 16:29
  • But depending on the method there might be up to a 3 days difference between the two results. This is too ambiguous – Dobromir Velev Jan 13 '21 at 16:36
  • BTW I calculate 1964. But it really depends (I think) on how you calculate precisely both methods. On the other hand that it means "3 months". It is also not a well defined way. But as human, I would just start from days: 13-14 = -1: so one day before current months (which it has strange consequences because we substract also months). I do not think there is a correct way – Giacomo Catenazzi Jan 13 '21 at 17:07
  • My mistake - I wrote the current year as 2020, I'm still living in the past. Edited to correct it. – Dobromir Velev Jan 13 '21 at 17:12

0 Answers0