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
- Python program to find number of days between two given dates
- Python program to convert seconds into hours, minutes and seconds
- Get Minutes from timestamp in Pandas-Python
- 30 minutes to machine learning
- NLP | Using dateutil to parse dates.
- Comparing dates in Python
- Python | Sort list of dates given as strings
- Formatting Dates in Python
- Matplotlib.dates.DateFormatter class in Python
- Matplotlib.dates.ConciseDateFormatter class in Python
- Matplotlib.dates.datestr2num() in Python
- Matplotlib.dates.epoch2num() in Python
- Matplotlib.dates.drange() in Python
- Matplotlib.dates.AutoDateFormatter class in Python
- Python | Difference between two lists
- Difference between Method Overloading and Method Overriding in Python
- Python | Measure similarity between two sentences using cosine similarity
- Python | Calculate Distance between two places using Geopy
- Make filled polygons between two curves in Python using Matplotlib
- Make filled polygons between two horizontal curves in Python using Matplotlib
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.
Improved By : alexanderlewang