Reputation: 1106
I am extracting timetamp from dictionary and then converting it into time-format.
When I try to compare with datetime.datetime.now()
using time delta it gets error:
dict={'Username': 'abc', 'Timestamp': '5/17/2017 16:52:35', 'GroupName': 'Cpositive'}
dictime=dict["Timestamp"]
dictime = datetime.datetime.strptime(dictime, '%m/%d/%Y %H:%M:%S')
print(dictime)
finaltime=(datetime.datetime.now() - datetime.timedelta(dictime))
print(finaltime)
output:
TypeError: unsupported type for timedelta days component: datetime.datetime
Upvotes: 0
Views: 1542
Reputation: 18126
I think, you want this, when you subtract 2 datetimes the result is timedelta:
>>> dictime = datetime.datetime.strptime(dictime, '%m/%d/%Y %H:%M:%S')
>>> finaltime=(datetime.datetime.now() - dictime)
>>> finaltime.days
0
>>> finaltime.seconds
1379
>>>
Upvotes: 2