undefinedfix
Sign in

Python calculates the number of minutes of the difference between two times, which is wrong when it is more than one day

daftarcaramenfub88 edited in Thu, 10 Dec 2020

Calculate the time minutes of the difference between T1 and T2. If it is more than half a minute, round it. The code is as follows: T2 is more than one day more than T1, but the result is still 2. What's wrong with my calculation?

import datetime

t1 = datetime.datetime(2017,3,4,8,49,0)
t2 = datetime.datetime(2017,3,5,8,50,30)

min =(t2 - t1).seconds/60
m = round(min)

print(m)
3 Replies
edmji
commented on Thu, 10 Dec 2020

(t2-t1).total_ Seconds () is all the seconds

creeper123123321
commented on Thu, 10 Dec 2020

(t2-t1).total_ seconds()

Amer
commented on Fri, 11 Dec 2020

I calculate that there will be one more day. I feel that the time difference is hard to use

lock This question has been locked and the reply function has been disabled.