0

I am getting format error when changing time in python.

This works fine

datetime.datetime.strptime('01:00AM', '%I:%M%p').time()

but this gives error

datetime.datetime.strptime('00:00AM', '%I:%M%p').time()

time data '00:00AM' does not match format '%I:%M%p'

1
  • 1
    Have you tried this datetime.datetime.strptime('12:00AM', '%I:%M%p').time(). Just a guess ;) Commented May 22, 2015 at 4:56

2 Answers 2

3

%I can be used only for 12 hour clock

For 24 hour clock

Try this

datetime.datetime.strptime('00:00AM', '%H:%M%p').time()

Sign up to request clarification or add additional context in comments.

Comments

1

For manual I found:

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

So I think 00:00AM should be represented as 12:00PM. Or you can use %H mentioned by fahad.

I think it's not an issue of 12-hour clock. When using %I, you have to start recording hour from 1 not 0, that's the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.