Search code examples
pythontimestrptime

Python: strptime not matching format


ValueError: time data '03-10-2011 04:35 PM' does not match format '%m-%d-%Y %I:M %p'

That looks like it matches to me?

 datetime = datestr + " " + timestr
 date_struct = time.strptime(datetime, "%m-%d-%Y %I:M %p")

Solution

  • You are missing a % right before the M:

     date_struct = time.strptime(datetime, "%m-%d-%Y %I:%M %p")