import datetime
def days(str1,str2):
date1=datetime.datetime.strptime(str1[0:10],"%Y-%m-%d")
date2=datetime.datetime.strptime(str2[0:10],"%Y-%m-%d")
num=(date1-date2).days
return num
def months(str1,str2):
year1=datetime.datetime.strptime(str1[0:10],"%Y-%m-%d").year
year2=datetime.datetime.strptime(str2[0:10],"%Y-%m-%d").year
month1=datetime.datetime.strptime(str1[0:10],"%Y-%m-%d").month
month2=datetime.datetime.strptime(str2[0:10],"%Y-%m-%d").month
num=(year1-year2)*12+(month1-month2)
return num
输入days(‘2018-04-23 08:18:09’,‘2017-03-21 10:19:33’) ,返回398
输入months(‘2018-01-23 08:18:09’,‘2017-03-21 10:19:33’),返回10