How to calculate the differences between two dates in hours with Python

1 Answer

0 votes
import datetime
 
d1 = datetime.datetime(2021, 6, 18)
d2 = datetime.datetime(2021, 6, 21)
 
days = abs(d1 - d2)
print(days)

diff_in_hours = days.total_seconds() / 3600
print(diff_in_hours)
 
 
 
 
'''
run:
 
3 days, 0:00:00
72.0
 
'''

 



answered Jun 22, 2021 by avibootz
...