What I want to do is perform time delta operations but rounding time to deciseconds (I am not sure if the term exists, but the following example should be self explanatory) instead of microseconds.
from datetime import datetime import time tick = datetime.now() time.sleep(1.5) tock = datetime.now() time.sleep(2.1) tock2 = datetime.now() diff1 = tock-tick diff2 = tock2-tick diff1 #0:00:01.500914 diff2 #0:00:03.601836 I would like the diff1 output to be 0:00:01.50, respectively diff2 0:00:03.60. But I do not want to format the result, I want to format the time values I am recording with tick and tock, basically to round them (actually just cut out everything that follows the two digits after the dot). The reason is, at some point in my program I want to compare the two diffs (as rounded time deltas) and only then I want to turn the result into string and format it.
I have tried doing it like this
tick = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-4] time.sleep(1.5) tock = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-4] diff1 = tock-tick #TypeError: unsupported operand type(s) for -: 'str' and 'str' But does not work since it already converts the time to string...