You've got a few problems... First, you're looking for strptime
and not strftime
. Second, strptime
is a method on datetime.datetime
, not datetime.datetime.date
. Third, you've got the order of the arguments mixed up. This should be what you want:
newtime = datetime.datetime.strptime(timevar, "%H:%M")
newtime -= datetime.timedelta(hours=5)
*Note, this gives you a date portion that is somewhere around January 1st, 1900. It seems like you only want the time portion, so that probably doesn't matter -- But I thought it would be worth mentioning.