Python | Difference between two dates (in minutes) using datetime.timedelta() method
To find the difference between two dates in Python, one can use the timedelta class which is present in the datetime library. The timedelta class stores the difference between two datetime objects.
To find the difference between two dates in form of minutes, the attribute seconds of timedelta object can be used which can be further divided by 60 to convert to minutes.
The following program takes two datetime objects and finds the difference between them in minutes.
Difference: 36 days, 10:04:20 Difference in minutes: 604.3333333333334
To get a more appropriate answer divmod() can be used which will return the fractional part of the minutes in terms of seconds:
Difference: 36 days, 10:04:20 Difference in minutes: 604 minutes 20 seconds