Search code examples
pythondatetimestrptime

Python datetime.strptime() ValueError


I don't understand why I get this error using datetime.strptime(), shouldn't this match?

ValueError: time data '2018-02-01 15:09:02.487779' does not match format '%Y-$m-$d %H:%M:%S.%f'

Mimimal example would be:

from datetime import datetime
print(datetime.strptime('2018-02-01 15:09:02.487779', '%Y-$m-$d %H:%M:%S.%f'))

Thank you in advance!


Solution

  • You have dollar signs instead of percent signs in parts of your format string:

    print(datetime.strptime('2018-02-01 15:09:02.487779', '%Y-$m-$d %H:%M:%S.%f'))
                                                              ^  ^