I am trying to parse a string date from a CSV in a Jupyter notebook:
from datetime import datetime
print(datetime.strptime('Aug 28, 2022', 'MMM d, yyyy'))
but I get the following error:
ValueError: time data 'Aug 28, 2022' does not match format 'MMM d, yyyy'
What am I doing wrong?
CodePudding user response:
Use other format string (format codes reference):
from datetime import datetime
print(datetime.strptime("Aug 28, 2022", "%b %d, %Y"))
Prints:
2022-08-28 00:00:00
CodePudding user response:
Try this out
from datetime import datetime
print (datetime.strptime ('Aug 28, 2022', '%b %d, %Y'))
To know about basic formats, https://www.geeksforgeeks.org/python-datetime-strptime-function/
CodePudding user response:
Use the following format
from datetime import datetime
print(datetime.strptime('Aug 28, 2022','%b %d, %Y'))
CodePudding user response:
The correct solution is:
datetime.strptime('Aug 28, 2022', '%b %d, %Y')
See https://www.geeksforgeeks.org/python-datetime-strptime-function/
CodePudding user response:
Check this out:(Explanation with samples)
We use notation that starts with % in datatime.strptime
datetime.strptime("Aug 28, 2022", "%b %d, %Y")
Thank you :)