I want to compare two dates and times with each other, and then use this information for other things. For example, if delta > 23hours to do it, elif delta > 11hours, to do it, etc. I thought it would be a reasonable way to write it, but python will not accept it! It says:
ValueError: 'h' is a bad directive in format '%m/%d/%Y%h:%m:%s'
Not a hstandard way to write a clock in Python ?: Oh
My dates are written in this format: "12/28/13 16:49:19", "m / d / yh: m: s", if that helps!
from datetime import datetime
date_format = "%m/%d/%Y%h:%m:%s"
then=(dictionary["date"])
now= time.strftime("%c")
a = datetime.strptime(str(then), date_format)
b = datetime.strptime(str(now), date_format)
delta = b - a
print(delta.hour)
source
share