datetime am pm python

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.

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

abdullah