can't compare datetime.datetime to datetime.date

There is a datetime.date() method for converting from a datetime to a date.

To do the opposite conversion, you could use this function datetime.datetime(d.year, d.month, d.day)


You can use the datetime.datetime.combine method to compare the date object to datetime object, then compare the converted object with the other datetime object.

import datetime

dt1 = datetime.datetime(2011, 03, 03, 11, 12)
day = datetime.date(2011, 03, 02)
dt2 = datetime.datetime.combine(day, datetime.time(0, 0))

print dt1 > dt2