start_date
and stop_date
are strings, which don’t support the -
operator. If you want to compute their (numerical) difference, define them as integers, i.e.
start_date = 20151231171500
stop_date = 20151231174500
or cast them to int
:
test = int(stop_date) - int(start_date)
Caveat: the difference of these numbers would be 3000, not 30. Not sure why you expect 30.
edit: so much for why you cannot substract a string from a string. To compute the actual time difference between dates, please see Martijn’s answer.
4
solved python error: unsupported operand type(s) for -: ‘str’ and ‘str’ [duplicate]