How do I calculate the difference in time in minutes for the following timestamp in Python?
2010-01-01 17:31:22 2010-01-03 17:31:22
Use datetime. strptime() to parse into datetime instances, and then compute the difference, and finally convert the difference into minutes.
We subtract time/dates in excel to get the number of days. Since a day has 1440 (24*60) minutes, we multiply the result by 1440 to get the exact number of minutes.
Get the minute value To calculate the value of minutes we need to first divide the total number of seconds by 3600 and take the remainder. Now to calculate the value of minutes from the above result we will again use the floor operator. A minute has sixty seconds hence we floor the seconds value with 60.
minutes_diff = (datetime_end - datetime_start).total_seconds() / 60.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With