Convert date string to date

Asked

Viewed 97 times

0

I need to convert the date of format 'Aug 29, 2019' to 06/08/2019 however I am not getting with strptime, Follow the error.

Valueerror: time data 'Aug 29, 2019' does not match format ' %m %d, %Y'

  • I don’t understand why the negative votes in the polls here in the O.R.

  • 1

    I share your question, some seem to be born knowing everything.

1 answer

2


You can use the datetime.strptime for this, see the example below:

import datetime
dataString = 'Aug 29, 2019'
dataObj = datahora = datetime.datetime.strptime(dataString,'%b %d, %Y')
print(dataObj.date())
#E pode formatar a saída do jeito que achar melhor
print(dataObj.date().strftime('%d-%m-%Y'))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.