Can't subtract departure time from current time

Hi Guys,

So I’am having a slight problem with the departure time in the trip planner api. I am trying to get the time until departure to print. To do this i am subtracting the current time from departure time. However, when I do this it gives me the error:

Traceback (most recent call last):
  File "C:\Python27\curl test", line 26, in <module>
    tdelta = datetime.strptime(timesTD, FMT) - realtime
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str'

I am unsure how to fix this and any help would be appreciated. Thanks very much. here is my code:

import requests, json
import os
import time
from datetime import datetime
FMT = '%H:%M'

busNumbers = ''

url = ''
payload = ''

headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'apikey ' }
r = requests.get(url, data=payload, headers=headers).json()

for buses in r['stopEvents'][0:6]:
    busNumbers = busNumbers + (buses['transportation']['disassembledName']) + ' '

for times in r['stopEvents'][0:6]:
    timesTD = (times['departureTimePlanned'][11:16])
    realtime ='%H:%M')
    tdelta = datetime.strptime(timesTD, FMT) - realtime

I’ll try and give you a better answer when I get home, but you can use combine as seen in this StackOverflow thread datetime - subtract two times in python - Stack Overflow to get the departure time.