Q:

Trouble with inputing current date into a list in a specific format

How do I put the current date into a list in the format I want?
import datetime
today = datetime.date.today()
lst=[]
lst.append(today)

lst[0]
>>> datetime.date(2018, 6, 22)
print(lst[0]) #found this code on another post (I have no idea how it works)
>>> 2018-06-22

I am trying to get "2018-06-22", which is the output of print(lst[0]), into my list but I can only get "datetime.date(2018, 6, 22)". Thanks in advance!
Update:
lst.append(str(today))

Using this code gets me the same results and I have no idea how it works.

A:

I would use the strftime() function built into the datetime module.  To do this with your code above, you only need to make one change:
import datetime
today = datetime.date.today()
lst=[]
lst.append(today.strftime('%Y-%m-%d'))
lst[0]

For more info, check out the docs:  https://docs.python.org/3/library/datetime.html

