Rjay155 Rjay155 - 1 year ago 124
Python Question

Unable to convert strptime properly

I was trying to take a string such as '2016-07-30T20:00:00' and convert it via

(string, '%Y-%d-%mT%H:%M:%S')

but I keep getting the error...

time data '2016-07-30T20:00:00' does not match format '%Y-%d-%mT%H:%M:%S'

when I had a string such as '2016-08-08T00:00:00' it would work but I'm not sure whats causing the error for the example above.

Answer Source

Clearly, you swapped between the month and the days, use:

(string, '%Y-%m-%dT%H:%M:%S')
#           --^--^--
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download