1👍
You need to find out what is my_datetime_object
but most likely because DateTime fields contain python datetime.datetime
objects, datetime.datetime
objects is composed of year, month, date, hour, minute, second, microsecond. So if you merely compare date
and hour
, sure you could get results, but you couldn’t guarantee that my_datetime_object
matches one of the records in your database that has the same minute, second and microsecond.
Try this quickly and you could see what does datetime look like, also django doc about DateTimeField
:
from datetime import datetime
date = datetime.now()
print date
Source:stackexchange.com