Python2で2つの日付間の月数を取得する

def diff_month(d1, d2):
    """ get months between two dates.
    >>> from datetime import date
    >>> diff_month(date(2012, 12, 1), date(2013, 3, 1))
    3
    """
    if d1 > d2:
        d1, d2 = d2, d1
    return (d2.year - d1.year)*12 + d2.month - d1.month 

datetime - Best way to find the months between two dates (in python) - Stack Overflow