from datetime import datetime
date1 = datetime.strptime(str('2011-08-15 12:00:00'), '%Y-%m-%d %H:%M:%S')
date2 = datetime.strptime(str('2012-02-15'), '%Y-%m-%d')
from dateutil import relativedelta
r = relativedelta.relativedelta(date1, date2)
r
Python: Difference of 2 datetimes in months