I have two timestamps:
time1= "2020-01-25T01:47:35.431Z"
time2="2020-01-25T02:02:57.500Z"
I used the following function to calculate the time interval between the two and return it in minute and round to two decimals.
def app_run2_min_diff(time1,time2):
time1= str(time1)
time1datetime.strptime(time1,'%Y-%m-%dT%H:%M:%S.%fZ')
time2= str(time2)
time2=datetime.strptime(time2,'%Y-%m-%dT%H:%M:%S.%fZ')
sec1=time1.strftime('%S')
sec2=time2.strftime('%S')
min_dif=round((float(sec2)-float(sec1)/60),2)
return min_dif
My logic is that to deduct the second difference first and then convert to minute. The min_dff I got is 34.42 , but the correct answer is 15.35. What's wrong with my logic above?