Stiley Stiley - 11 months ago 63
Python Question

Python - difference between time

Looking for easiest way to calculate the difference between 2 python times and display the millisecond delta

I have 2 times

startTime =

do some stuff...


This works fine and when I log the times out and I get something like this in my logs...

RequestStartTime = 08:56:19.188999

ResponseTime = 08:56:19.905999

When I try to simply subtract them like this

delta = endTime - startTime

I get the following error

unsupported operand type(s) for -: 'time' and 'time'

All I want to do is show the difference in microseconds and I can't figure it out

I want to show is
717000 ms

Answer Source

If you just use the result of now(), and don't convert them to times, you can take the difference & extract the bits you want in the form you want; for example:

startTime =
delta = endTime - startTime
print str(delta).split(":")[2]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download