I'm trying to extract the date and time from a string establish the delta between that and the current date and time. I tried to convert the regex output from a list to a string and it shows as type=string but is in the following format - ('18:06:39', 'Jan 30 2020').
import re from datetime import datetime, timedelta, date string = 'configuration change at 18:06:39 EET Thu Jan 30 2020 by netbrain' chg_date = re.findall(r"(\d{2}:\d{2}:\d{2}) \w+ \w+ (\w{3} \d{2} \d{4})", string) chg_date_str = ''.join(map(str, chg_date)) now = datetime.now() now_format = now.strftime("%H:%M:%S, %b %d %y") time_difference = now_format - chg_date_str print(chg_date_str) print(time_difference) I get the following error.
Traceback (most recent call last): File "C:/Users/MattSherman/Desktop/Python/y.py", line 15, in <module> time_difference = now_format - chg_date_str TypeError: unsupported operand type(s) for -: 'str' and 'str'