Trying to subtract two dates and get a result in hours(greater than 24 hours time period) in python
This is what I have tried:
currentdate = datetime.now()
# gets the date from the website
lastcrawl = driver.find_element_by_xpath('//*[@id="last-15336"]/h4').text
# convert string into time format
formatlastcrawl = datetime.strptime(lastcrawl, '%b %d %H:%M')
# converts into the time format - April 28, 11:24
newformatlastcrawl = formatlastcrawl.strftime('%b %d %H:%M')
print newformatlastcrawl
# substracts 24 hours of the current date(because the website crawl happens every 24 hours) + 2 hours(to give enough time to finish the crawl)
substractdate = (currentdate - timedelta(hours=26)).strftime("%b %d %H:%M")
print substractdate
# changes the format of the current date. For example - Nov 12
formatcurrentdate = currentdate.strftime("%b %d %H:%M")
print formatcurrentdate
a = (substractdate - newformatlastcrawl)
print a
When I try to subtract it I get this error:
a = (substractdate - newformatlastcrawl).strptime("%b %d %H:%M") TypeError: unsupported operand type(s) for -: 'str' and 'str'
I would like to get the answer in hours only. Also, time values can be greater than 24 hours