我想在python中从当前日期比较/减去两个日期的到期日期,并对该减法应用一个条件,如果差异> 0天,则通过将差异乘以每天罚款来计算罚款
from datetime import date
a=date.today()
issuedate=date(2019,5,9)
duedate#should be 5 days after issue date i can't find the method for doing this
check=a-duedate
# if check>0days:
# print(check days*40)
答案 0 :(得分:0)
您需要在datetime模块中使用timedelta函数:
from datetime import date
import datetime
a=date.today()
issuedate=date(2019,5,9)
duedate = issuedate+datetime.timedelta(days=5)
check=a-duedate
print(check>=datetime.timedelta(days=0))
答案 1 :(得分:0)
从日期时间导入timedelta
duedate = issuedate + timedelta(days=5)
check=(a-duedate).days