welcome to Python
If You're using an IDE like Visual Studio Code and an extension for intellisense like Pylance You can do something like this:
from datetime import datetime, timedelta
def subtractMinutes(minutes: int = 40) -> str:
return datetime.today()-timedelta(minutes=minutes)
Intellisense would tell You that Your function is returning a "date" object instead of a "str" object
Date objects store all information about the date, from milliseconds to years
You can set the seconds of the date object to zero, but it will still print the full date object
What You want is a string, a formatted string! So the way to fix Your function would be
from datetime import datetime, timedelta
DATE_FORMAT = "%d-%m-%Y"
def subtractMinutes(minutes: int = 40) -> str:
## strftime read "format date as string"
return datetime.strftime(
datetime.today()-timedelta(minutes=minutes),
DATE_FORMAT
)
For a reference to other formats You can visit this site
Happy hacking!