comparing datetime with date
Pierre Fortin
pfortin at pfortin.com
Tue Sep 14 20:37:29 EDT 2004
On Wed, 15 Sep 2004 09:24:03 +1000 Graeme wrote:
> This is very interesting because if you continue further and coerce both
> to strings you get:
>
> >>> print str(y) == str(y)
of course: ^ ^ :^)
> True
> Even though there string values are different they still match?
>>> today = datetime.date(2004,9,14)
>>> yesterday = datetime.date(2004,9,13)
>>> now = datetime.datetime(2004,9,14,20,0)
>>> now == today
True
>>> now == yesterday
False
>>>
Looks like date and datetime have 3 arguments and minimum 3 args
respectively, so the comparison appears to simply use the minimum data
available... when given more data to compare, we get:
>>> minute_ago = datetime.datetime(2004,9,14,19,59)
>>> minute_ago == now
False
> All i can assume is that when a Date / DateTime comparision is made the
> 'lowest denominator' i.e Date is used but I may be very wrong
I agree...
> Will watch this thread closely
More information about the Python-list
mailing list