S
S
ShagolChannel2022-01-22 19:24:57
Python
ShagolChannel, 2022-01-22 19:24:57

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)

I tried to pass the list, but the error also falls

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nesterov, 2022-01-22
@AlexNest

Go read Lutz.
As you get to the functions and their arguments, you will understand what you are doing wrong.

V
Vladimir Kuts, 2022-01-22
@fox_12

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 question

Ask a Question

731 491 924 answers to any question