I have a function which returns in YYYY-MM-DD i want to add 10 days to this date and check if today is the date. how can i do that.
def date_return:
return YYYY-MM-DD
CodePudding user response:
- Use
datetime.date.fromisoformat
to turn YYYY-MM-DD into adatetime.date
. - Use
datetime.timedelta(days=10)
to add 10 days to that date. - Compare it to
datetime.date.today()
.
>>> import datetime
>>> yyyymmdd = "2022-09-04"
>>> print(
... datetime.date.fromisoformat(yyyymmdd) datetime.timedelta(days=10)
... == datetime.date.today()
... )
True