I am trying to set a function that subtracts a month from an specific date format as an argument, and returns a date in the same specific date format,
This argument is given by today's month and year: 01/%m/%Y.
Actual code:
from datetime import datetime
import dateutil.relativedelta
actual_date = datetime.now()
actual_date = "{}/{}/{}".format('01', actual_date.month, actual_date.year)
def set_date(actual_date):
print(actual_date - dateutil.relativedelta.relativedelta(months=1))
Here's the output when set_date() is tested:
set_date(actual_date)
TypeError: unsupported operand type(s) for -: 'str' and 'relativedelta'
Expected output should look like this:
01/12/2020