Javier Allende
Javier Allende

Reputation: 3

Convert string (Jun 6, 2019 9:29:29 AM) into datetime (Y-M-D H:M:S) with Python -

I've the following date: Jun 6, 2019 9:29:29 AM in string format with python and I want to convert this string into 2019-06-06 09:29:29. I've tried with strptime but I always get an error in the processing:

from datetime import datetime
date_string = "Jun 6, 2019 9:29:29 AM"
date_object = datetime.strptime(date_string, "%m %d, %Y %H:%M:%S %p")

Any suggestions?

Upvotes: 0

Views: 129

Answers (2)

Javier Allende
Javier Allende

Reputation: 3

fecha="May 29, 2019 9:10:07 PM"
fecha = datetime.strptime(fecha,"%b %d, %Y %H:%M:%S %p")
fecha = str(fecha)
print fecha

2019-05-29 09:10:07

the result is incorrect :( , the transformation from PM isnt correct

regards

Upvotes: 0

Rıdvan Sözen
Rıdvan Sözen

Reputation: 36

>>> from datetime import datetime
>>> date_string = "Jun 6, 2019 9:29:29 AM"
>>> date_object = datetime.strptime(date_string,"%b %d, %Y %H:%M:%S %p")
>>> print(date_object)
2019-06-06 09:29:29

Upvotes: 2

Related Questions