Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96685 > unrolled thread

Re: datetime.datetime.today()

Started byMichiel Overtoom <motoom@xs4all.nl>
First post2015-09-16 17:01 +0200
Last post2015-09-16 17:01 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: datetime.datetime.today() Michiel Overtoom <motoom@xs4all.nl> - 2015-09-16 17:01 +0200

#96685 — Re: datetime.datetime.today()

FromMichiel Overtoom <motoom@xs4all.nl>
Date2015-09-16 17:01 +0200
SubjectRe: datetime.datetime.today()
Message-ID<mailman.646.1442415769.8327.python-list@python.org>
This bit me once. I was comparing a date to a datetime, both representing the same day, so I expected them to be the same, but I was wrong. What I should have done was extracting the date of the datetime with the .date() function, and only then compare it to the other date:

>>> import datetime
>>> a = datetime.datetime.today()
>>> a
datetime.datetime(2015, 9, 16, 16, 57, 45, 150069)
>>> b = datetime.date.today()
>>> a == b
False
>>> a.date()
datetime.date(2015, 9, 16)
>>> a.date() == b
True

Greetings,

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web