def diff_months(sub1, sub2):
    """ calculates the differences in months between two dates """
    years = 0
    months = 0
    if (sub2.year > sub1.year):
        years = max(0, sub2.year - (sub1.year + 1))
        months = (12 - sub1.month + 1) + sub2.month
    elif (sub2.year == sub1.year):
        months = sub2.month - sub1.month
    elif sub2.year < sub1.year:
        years = min(0, sub2.year + 1 - sub1.year)
        months = -(12 - sub2.month + 1) - sub1.month
        
    return years * 12 + months