How to get the days between dates?

There are two dates: 1) 16022020; 2)16022019. How to display all days in this period?
April 7th 20 at 15:21
2 answers
April 7th 20 at 15:23
Solution
from datetime import datetime

firstDate = '16022020'
secondDate = '01012020'

f_date = datetime.strptime(firstDate,'%d%m%Y').date()
s_date = datetime.strptime(secondDate,'%d%m%Y').date()

print((f_date-s_date).days)

Prints: 46

from datetime import datetime,timedelta,date

firstDate = '16022020'
secondDate = '01012020'

f_date = datetime.strptime(firstDate,'%d%m%Y').date()
s_date = datetime.strptime(secondDate,'%d%m%Y').date()

delta = timedelta(days=1)
while s_date <= f_date:
 print (s_date.strftime("%d.%m.%Y"))
 s_date += delta

Conclusion:
01.01.2020
02.01.2020
03.01.2020
04.01.2020
...
12.02.2020
13.02.2020
14.02.2020
15.02.2020
16.02.2020
DD.mm.yyyy - henri.Marks commented on April 7th 20 at 15:26
April 7th 20 at 15:25

Find more questions by tags Python