我有一个日期“10/10/11(m-d-y)”,我想用Python脚本添加5天。请考虑一个在月底也适用的通用解决方案。
我使用以下代码:
import re
from datetime import datetime
StartDate = "10/10/11"
Date = datetime.strptime(StartDate, "%m/%d/%y")
打印日期->正在打印'2011-10-10 00:00:00'
现在我想在这个日期上加5天。我使用了以下代码:
EndDate = Date.today()+timedelta(days=10)
返回以下错误:
name 'timedelta' is not defined
使用时间增量你可以做:
import datetime
today=datetime.date.today()
time=datetime.time()
print("today :",today)
# One day different .
five_day=datetime.timedelta(days=5)
print("one day :",five_day)
#output - 1 day , 00:00:00
# five day extend .
fitfthday=today+five_day
print("fitfthday",fitfthday)
# five day extend .
fitfthday=today+five_day
print("fitfthday",fitfthday)
#output -
today : 2019-05-29
one day : 5 days, 0:00:00
fitfthday 2019-06-03