Calculating months difference (Age Calculator)

Hello everyone! I've recently just started a new project to create an Age calculator in c++. I have made it so that it now successfully calculates your age. I also want it to calculate how old you are in months (and days. One step at a time) but I can't figure out how to do it.

I could do a "simple" subtraction but what if its the 2nd of november today and my birthday is the 21st February next year? How do I make it calculate the months in the right way?
Do the simple subtraction first. Then compare the days of the month to see if you need to subtract a month.

closed account (48T7M4Gy)
2/11/2015 to 21/2/2016

Future - Past:
2016 - 2015 = 1 x 12 = 12 months
2 - 11 = -9
12 - 9 = 3 months
Kemort what I meant was:

You are 20 years

8 months
23 days old.

But now lets say I found out the difference which is 3, what do I do to find out how old I am?
closed account (48T7M4Gy)
If your question is how many days then you continue the calculation. However you'll quickly realize that this is not really all that meaningful because months vary in length. So your age is better described in years plus weeks and/or days even though leap years also intervene.

However, if you need to be absolutely accurate with months and days (and taking into account leap years), one way is to calculate from the start/end of the month in each case, in order to get the days right, and then add that result to the months number.

That means 2/11/2015 to 21/2/2016 is 0 years 2 (whole calendar) months and 49 days, which is a bit 'ordinary'.
Topic archived. No new replies allowed.