This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: datetime.strptime fails to parse AM/PM correctly
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: aepage, zach.ware
Priority: normal Keywords:

Created on 2016-02-09 15:08 by aepage, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg259936 - (view) Author: Andrew Page (aepage) Date: 2016-02-09 15:08
##  It appears that strptime is ignoring the AM/PM field
from datetime import datetime
d1 = datetime.strptime("1:00 PM", "%H:%M %p")
d2 = datetime.strptime("1:00 AM", "%H:%M %p")
d1.hour, d2.hour
(1, 1) # d1 should be 13
d1 == d2
True # and these should not be equal
msg259941 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-02-09 15:59
This is a documented peculiarity of the %p format code, see the '%p' entry in the table at [1], note 3 in particular.

>>> from datetime import datetime
>>> datetime.strptime('1:00 PM', '%H:%M %p').hour
>>> datetime.strptime('1:00 PM', '%I:%M %p').hour

Date User Action Args
2022-04-11 14:58:27adminsetgithub: 70509
2016-02-09 15:59:54zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg259941

resolution: not a bug
stage: resolved
2016-02-09 15:08:56aepagecreate