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
- Comparing dates in Python
- Python | Sort list of dates given as strings
- Python program to find number of days between two given dates
- Difference between Method and Function in Python
- Python program to convert seconds into hours, minutes and seconds
- Python set operations (union, intersection, difference and symmetric difference)
- Python PIL | ImageChops.add_modulo() and ImageChops.difference() method
- 30 minutes to machine learning
- NLP | Using dateutil to parse dates.
- Difference between C and Python
- Python Set | difference()
- Difference between == and is operator in Python
- Difference between various Implementations of Python
- Python | Difference between two lists
- Python | Set Difference in list of dictionaries