Hi,
Consider a method call first.differenceInYears(second) where first and second are MyDate objects.
We have three general cases:
1. Both dates are equal
2. first is before second
3. second is before first
Case #1 is trivial so we skip that. We also notice that cases #2 and #3 are essentially the same, with just the dates inverted. So if we can solve one of those, we know how to solve the other. So let us focus on case #2.
NB: I'll be using the format year/month/day, so 2015/1/2 is January 2nd, 2015.
Let us consider a few sub-cases in the format day.month.year, so :
1. first = 2014/1/2, second = 2015/1/1
2. first = 2013/1/2, second = 2015/1/1
3. first = 2013/1/1, second = 2015/1/2
In sub-case #1, the difference is 0 full years, in #2 it's 1 full year and in #3 it is 2 full years.
I'd like you to write those dates down on paper and figure out the pattern there.
I'll give you one more hint: Sometimes, the correct answer is (first.year - second.year - 1) and sometimes it is just (first.year - second.year).
If you need more help, do not hesitate to ask :)
Yours,
Leo