Reputation:
I am trying to use datetime.now() with timedelta and soustract it so I get the time for yesterday.
yesterday = datetime.now().strftime("%Y-%m-%d") - timedelta(days=1)
But when I tried to do it, it gives me this error :
unsupported operand type(s) for -: 'str' and 'datetime.timedelta'
So I tried to convert it to an int but with no success.
Upvotes: 0
Views: 92
Reputation: 47354
This part of code datetime.now().strftime("%Y-%m-%d")
return formated datetime string. You can find strftime()
description here.
You need to substract timedelta first and then apply formatting to the result:
yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
Upvotes: 1