Day difference between two dates in python

engrmahabub
Mahabubur Rahman
Published on Sep, 25 2023 1 min read 0 comments
image

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)

Output :

6

 

 

 

0 Comments