0

I'm executing a command print(end_date - start_date) and I get in console:

3 days, 0:00:00
10 days, 0:00:00
11 days, 0:00:00
11 days, 0:00:00

etc.

I want to make a condition that

if all end_data - start_data >= 2 (days):

    print('OK')
else:
    print('Error')

How can I put 2 days instead of 2 (int number)?

TrebledJ
  • 8,713
  • 7
  • 26
  • 48
  • you could use [`timedelta`](https://docs.python.org/3/library/datetime.html?highlight=timedelta#datetime.timedelta): `if date1 - date0 >= timedelta(days=2): ...` – hiro protagonist Apr 09 '19 at 09:51
  • See https://stackoverflow.com/questions/8419564/difference-between-two-dates-in-python – glhr Apr 09 '19 at 09:52

1 Answers1

0
from datetime import timedelta
timedelta(days = 2) # 2 days, 0:00:00 (<class 'datetime.timedelta'>)

Here is nice article how to manipulate date and time in Python : https://www.programiz.com/python-programming/datetime

ncica
  • 7,015
  • 1
  • 15
  • 37