I need to see if a date has more than X days. How can I do this in Python?
I have tested something like:
if datetime.date(2010, 1, 12) > datetime.timedelta(3):
I got the error:
TypeError: can't compare datetime.date to datetime.timedelta
Any clue on how to achieve this?
You can't compare a
datetimeto atimedelta. Atimedeltarepresents a duration, adatetimerepresents a specific point in time. The difference of twodatetimes is atimedelta. Datetimes are comparable with each other, as aretimedeltas.You have 2 options:
datetimefrom the one you've given, and compare the resultingtimedeltawith thetimedeltayou've also given.timedeltato adatetimeby adding or subtracting it to anotherdatetime, and then compare the resultingdatetimewith thedatetimeyou've given.