[Solved] How to convert 12 hour string into 24 hour datetime? [closed]


The main problem with your format is that Python does not support anything more granular than microseconds, as explained here. In fact, assuming you have 000 as the last three decimals of seconds, you can use the format below.

from datetime import datetime
datetime_object = datetime.strptime('24/NOV/18 05:15:00.000000000 AM', '%d/%b/%y %I:%M:%S.%f000 %p')

If you cannot make that assumption, this dirty hack should work:

from datetime import datetime
s="24/NOV/18 05:15:00.000000000 AM"
s = s[:-9] + s[-6:]
datetime_object = datetime.strptime(s, '%d/%b/%y %I:%M:%S.%f %p')

solved How to convert 12 hour string into 24 hour datetime? [closed]