比较 python 中的日期并应用比较条件
Comparing date in python and applying a condition on comparison
我想compare/subtract 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)
您需要使用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))
使用时间增量
从日期时间导入时间增量
duedate = issuedate + timedelta(days=5)
check=(a-duedate).days
我想compare/subtract 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)
您需要使用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))
使用时间增量
从日期时间导入时间增量
duedate = issuedate + timedelta(days=5)
check=(a-duedate).days