import datetime
prev_day = datetime.datetime(2017, 12, 31)
cur_day = datetime.datetime(2018, 1, 31)
diff = cur_day - prev_day
print(diff)
31 days, 0:00:00
diff是datetime.timedelta类型的数据
datetime.timedelta类型转换为int类型:diff.days
import datetime
prev_day = datetime.datetime(2017, 12, 31)
cur_day = datetime.datetime(2018, 1, 31)
diff = cur_day - prev_day
print(diff)
print(diff.days)
print(type(diff.days))
31 days, 0:00:00
31
<class 'int'>