Search code examples
pythonpython-datetimestrptime

datetime.strptime raises valueError because of format mismatch


I am trying to parse a string to a datetime field but it raises the following error:

ValueError: time data '15 Dec 1995 00:00 AM' does not match format '%d %b %Y %I:%M %p'

I have checked the python documents and I don't see where the format mismatch is happening. Can anyone help me find where this format error is?


Solution

  • Looking at the docs:

    %I
    Hour (12-hour clock) as a zero-padded decimal number.
    01, 02, …, 12

    So 00:00:00 is not a valid time under the %I format, given that 00:00:00 AM should actually be 12:00:00 PM