天数差
python3比较两个日期之间的天数
from datetime import date
d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d1 - d0
print(delta.days)
参考
- https://docs.python.org/library/datetime.html
- https://stackoverflow.com/a/151211/2007704
加上天数
import datetime
s = '2021-10-29'
days = 180
start = datetime.datetime.strptime(s,'%Y-%m-%d')
end = start + datetime.timedelta(days=days)
print(end) // datetime.datetime(2022, 4, 27, 0, 0)