I am using the function today() of the datetime object to obtain the current date, if I want to subtract a day to have the date of the previous day it will not let me:}
today=datetime.today()-1
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'int'
Is there another function to subtract or add days?
To add or subtract using the datetime class, you need to also import timedelta from datetime.
Here are some examples:
ADD 60 SECONDS
SUBTRACT 15 MINUTES:
I hope it helps, greetings.
to subtract the day from the value returned by datetime.today() you can use timedelta