comparing datetime with date

Tim Peters tim.peters at gmail.com
Tue Sep 14 23:26:49 CEST 2004


[Diez B. Roggisch]
>> Try making a datetime-object from your date, with zeros for the time part -
>> then you'll get what you want.

[Peter Hansen]
> While trying to provide my first answer, I thought of suggesting
> this, but there doesn't appear to be a simple way of doing it.

datetime.datetime has a class constructor for building a datetime out
of a date and a time, so this can be done via a simple one-liner:

>>> import datetime
>>> t = datetime.date.today()
>>> t
datetime.date(2004, 9, 14)
>>> datetime.datetime.combine(t, datetime.time())
datetime.datetime(2004, 9, 14, 0, 0)
>>>



More information about the Python-list mailing list