Search code examples
pythonstrptime

Getting ValueError while trying to convert str to datetime


The error that I seem to get is

ValueError: time data '2010-10-15' does not match format '%y-%m-%d'

I am failing to understand what is wrong here. Could someone please guide to what am I missing?

from datetime import datetime

year = datetime.strptime(data[1].split(" ")[0], "%y-%m-%d")

Solution

  • Try this parsing String : "%Y-%m-%d". It should work. Refer the python docs