I am having date troubles with a python script I am writing. Why is this false? I am not understanding why 00:00:00
is still present even though I have explicitly requested only the day, month, year?
date1 = datetime.strptime('22 Dec 2016', '%d %b %Y') <-- 2016-12-12 00:00:00
date2 = datetime.today().date()
print(date1==date2) # False
You are comparing a
datetime
object and adate
object;datetime.strptime()
always produces adatetime
instance; even though the time is set to midnight, that's still a date and time combination.To compare only dates, you need to do so explicitly.
Either:
or