comparing datetime with date

Donnal Walter donnal at donnal.net
Tue Sep 14 07:52:14 EDT 2004


I was very surprised to discover that

 >>> import datetime
 >>> x = datetime.date(2004, 9, 14)
 >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15)
 >>> print x == y
True

How can these two objects be considered equal? Is there a *general* way 
to test for date != datetime as well as 4.5 != 4.6?

Donnal Walter
Arkansas Children's Hospital





More information about the Python-list mailing list