0

i want to compare/subtract two date's due date from current date in python and apply a condition on this subtraction that if the difference is >0 days then calculate fine by multiplying difference with fine per day

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) 
1
  • Please explain more clearly what you want to do Commented May 23, 2019 at 11:28

2 Answers 2

1

You need to use the timedelta function in the datetime module:

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)) 
Sign up to request clarification or add additional context in comments.

Comments

1

Use timedelta

from datetime import timedelta

duedate = issuedate + timedelta(days=5) check=(a-duedate).days 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.