Only you know the requirements you must meet, but the fact that there are 183 days and 43200 SI seconds between these two dates highlights an inherent subjectivity in determining how many months that "really" is.
Is a month 30 days, or (365 / 12) days, or ((365 * 4 + 1) / 48) days, or ...?
Is a day always 86400 seconds, or do you count historical leap seconds, or do you predict leap seconds for future dates?
These decisions affect the answer the algorithm you appear to desire will give you for certain input dates that are close to these boundaries.
In my opinion, it is more intuitive to consider months as atomic units of time for this purpose and use this formula: (date2.year - date1.year) * 12 + (date2.month - date1.month)