Answer the question
In order to leave comments, you need to log in
How to pass date for datetime in function argument?
I want to make a function that will take a date as an argument and write it to the datetime type. This can be implemented without an additional function: datetime.date(2022, 1, 22), but is it possible to somehow pass the date as an argument?
def get_date(date):
date = datetime.date(date)
get_date(2021, 1, 12)
Answer the question
In order to leave comments, you need to log in
Go read Lutz.
As you get to the functions and their arguments, you will understand what you are doing wrong.
from datetime import datetime
def get_date(inp):
return datetime(*inp).date()
dat = (2021, 1, 12)
get_date(dat)
# datetime.date(2021, 1, 12)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question