How can I account for period (AM/PM) using strftime? How can I account for period (AM/PM) using strftime? python python

How can I account for period (AM/PM) using strftime?


The Python time.strftime docs say:

When used with the strptime() function, the %p directive only affects the output hour field if the %I directive is used to parse the hour.

Sure enough, changing your %H to %I makes it work.


format = '%Y-%m-%d %H:%M %p'

The format is using %H instead of %I. Since %H is the "24-hour" format, it's likely just discarding the %p information. It works just fine if you change the %H to %I.


You used %H (24 hour format) instead of %I (12 hour format).