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
- Python program to convert seconds into hours, minutes and seconds
- Difference between Method and Function in Python
- Python set operations (union, intersection, difference and symmetric difference)
- 30 minutes to machine learning
- Python PIL | ImageChops.add_modulo() and ImageChops.difference() method
- NLP | Using dateutil to parse dates.
- Difference between C and Python
- Python Set | difference()
- Difference between Python and C#
- Difference between various Implementations of Python
- Difference between == and is operator in Python
- Python | Difference between two lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.