How to convert a string like "28 JUL 1795" to a date with the format of"%B %d, %Y"? [closed]

StackOverflow https://stackoverflow.com/questions/22155287

Pregunta

I used following line to transfer my date string but it gave me an error.

print datetime.datetime.strptime(arg, '%d %b %Y').date().strftime("%B %d, %Y")

ValueError: time data '28 JUL 1795' does not match format '%B %d %Y'

No hay solución correcta

Otros consejos

This behaviour is not reproduceable. The following works as intended:

>>> datetime.datetime.strptime('28 JUL 1995', '%d %b %Y').date().strftime('%B %d, %Y')
'July 28, 1995'

Maybe your input string is not what you expect it to be.

Use like this

time.strptime("28 JUL 1795", "%d %b %y")

heres a link to strptime method which will convert it for you http://docs.python.org/2/library/time.html#time.strptime

heres a link to a similiar question Converting string into datetime

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top