I found this function to calculate the time difference in seconds. I have a database with this time format (variable g
). I converted them so I got both the same time formats. but I gives me this error:
2018,12,09,15,34,33
2018,12,09,16,42,54
Traceback (most recent call last):
File "test.py", line 12, in <module>
(v-j).total_seconds()
TypeError: unsupported operand type(s) for -: 'str' and 'str'
What is wrong with this piece of code?
import datetime
g = '2018-12-09 15:34:33'
d = datetime.datetime.strptime(g, '%Y-%m-%d %H:%M:%S')
v = d.strftime('%Y,%m,%d,%H,%M,%S')
j = datetime.datetime.now().strftime('%Y,%m,%d,%H,%M,%S')
print v
print j
(v-j).total_seconds()