Here's a small snippet that I'm trying to execute:
> Gt; & Gt; Date Time From Import * & gt; & Gt; & Gt; Item_date = datetime.strptime ('7/16/10', '% m /% d /% y') & gt; & Gt; & Gt; From_date = date.today () - TimeDelta (day = 3)> gt; & Gt; & Gt; Print Type (item_data) & lt; Type 'datetime.datetime' & gt; & Gt; & Gt; & Gt; Print Type (from_data) & lt; Type 'datetime.date' & gt; & Gt; & Gt; & Gt; If item_data & gt; From_data: ... print 'item is new ... traceback (most recent call final): File "& lt; stdin>", line 1, & lt; Module & gt; TypeError: datetime.datetime can not be compared to datetime.date I can not seem to compare date and date time values. What would be the best way to compare them? Should I change date or vice versa?
(There is a small question but it seems a bit confusing.)
Use to date a date:
if item_date.date ()> From_data: Alternatively, you can use it in place of date.today () .
to / data-to_data.rele (hour = 0, minute = 0, seconds = 0, microsecond = 0) Can use later part
Comments
Post a Comment