Date difference in minutes in Python

Date difference in minutes in Python or Django?

How do I calculate the difference in days for the following datetime in Python?

2018-01-01 15:00:00
2018-01-05 15:00:00

from datetime import datetime

datetime_fmt = '%Y-%m-%d %H:%M:%S'
date1 = datetime.strptime('2010-01-01 17:31:22', datetime_fmt )
date2 = datetime.strptime('2010-01-03 17:31:22', datetime_fmt )

days_diff = (d2-d1).days
print (days_diff)
> 4

 

source:
https://docs.python.org/3/library/datetime.html#

Leave a Reply

Your email address will not be published. Required fields are marked *