Mohsen Amiri
Mohsen Amiri

Reputation: 175

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?

Upvotes: 1

Views: 223

Answers (2)

nikeros
nikeros

Reputation: 3369

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

Upvotes: 2

adshin21
adshin21

Reputation: 188

There is no 00:00 time in 12-hour clock format, you should either write this as 12:00 or use a 24-hour format with %H.

Upvotes: 1

Related Questions