Day difference between two dates in python

Mahabubur Rahman
0

 Day difference between two dates in python

-------------------------------------

Solution:

  • Import datetime
  • get current datetime
  • convert the datetime to date using python date() function
Step 1: Import date from datetime

>>> from datetime import date

Step 2: Set start date and end date  -

>>> start_date= date(2021, 6, 2)
>>> end_date = date(2021, 6, 8)

Step 3: Get date deference - 

>>> delta = end_date - start_date
>>> print(delta.days)
6

Post a Comment

0Comments
Post a Comment (0)