0

I'm attempting to strip a datetime object from a string, but for some reason the period (AM/PM) is being ignored. Below is some sample code to demonstrate the problem:

from datetime import datetime

timeFormat = '%m/%d/%Y %H:%M%p'
amString = "07/26/1994 2:00AM"
pmString = "07/26/1994 2:00PM"

amDate = datetime.strptime(amString, timeFormat)
pmDate = datetime.strptime(pmString, timeFormat)

Which is great -- but if I print each date to reveal the value:

>>> pmDate
datetime.datetime(1994, 7, 26, 2, 0)
>>> amDate
datetime.datetime(1994, 7, 26, 2, 0)
>>> amDate == pmDate
True

I assumed the amDate and pmDate variables should not be equal. Is this common behavior for Python 2.7's datetime module or am I missing something obvious? If it is true that periods are useless to datetime.strptime, why?

Casey Falk
  • 2,617
  • 1
  • 18
  • 29

0 Answers0