Reputation: 59
I am not why I am getting error in below code -
from datetime import datetime
import time
start =datetime.now().replace(microsecond=0).isoformat(' ')
end = datetime.now().replace(microsecond=0).isoformat(' ')
print(f" Total Time taken by check run is {end - start}[hh:mm:ss]")
Error is coming in the print statement saying:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Upvotes: 1
Views: 60
Reputation: 5746
isoformat()
returns a string
.
If you remove isoformat()
from your datetime object
, you will be able to subtract the time difference.
start = datetime.now().replace(microsecond=0)
end = datetime(2021, 4, 9, 17, 15, 00)
print(f" Total Time taken by check run is {end - start}[hh:mm:ss]")
#Total Time taken by check run is 1:26:18[hh:mm:ss]
Upvotes: 2