D
D
demortall2021-11-21 14:06:48
Python
demortall, 2021-11-21 14:06:48

ValueError: time data '2021-11-21' does not match format '%a %b %d %H:%M:%S %Y'?

today = date.today()
strftime("%Y-%m-%d", strptime(today.strftime('%Y-%m-%d')))

Outputs ValueError: time data '2021-11-21' does not match format '%a %b %d %H:%M:%S %Y'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2021-11-22
@dmshar

Can you explain what you are doing here?
today.strftime('%Y-%m-%d') - OK, of course, we translate the date into a string.
strptime(today.strftime('%Y-%m-%d')) - well, suppose we want to convert the string back to the "datatime" format. But without specifying the format parameter, you accept the default format "%a %b %d %H:%M:%S %Y"
And now the main question is
strftime("%Y-%m-%d", strptime(today .strftime('%Y-%m-%d'))) - where is the first parameter - data, where is the second parameter - format?
So I can only suspect that you meant to write something like

today = date.today()
datetime.strftime( datetime.strptime(today.strftime('%Y-%m-%d'),'%Y-%m-%d'),"%Y-%m-%d")

which, although it will work, will still do something absolutely meaningless.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question