comparing datetime with date

Diez B. Roggisch deetsNOSPAM at web.de
Thu Sep 16 08:25:45 EDT 2004


> There are several meanings. A date is valid for 24 hours. If you think
> of a date as point in time there is usually a time part of 0:00 silently
> added. No matter which meaning you prefer: Evaluating 2004-09-16 ==
> 2004-09-16T3:14 as true is very surprising.

Its a matter of taste - I've seen plenty of worarounds in my life -
especially in database-related code - that exactly tries to create that
behaviour of forced equality. The reason beeing that there are not two
distinct types date and datetime, but only the latter.

A date is all the times from 0:00 to 23:59 only if you you view it with the
greater resolution of datetime - if you restrict yourself to dates, its one
point.

I don't say that your POV isn't correct - but neither is the one currently
implemented: If you compare apples to oranges, it depends on what you focus
on: If you're strict, you'd say they're different. If you focus on them
beeing fruits, you might say they are equal.

We deal here with ternary logic - True, False and Bottom/Failure. One can
very well argue, that your example

int(3) == 3.14

shouldn't work at all, but produce an exception, forcing the programmer to
think about explicit conversion. Then you are in ADA-World :)

But as python tries to be a convenient language, they silently are coerced
to maching types and compared then. The same happened here - with a for
some people surprising outcome, for others it makes life much easier.


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list