AnsweredAssumed Answered

Arcpy ValueError: unconverted data remains: PM

Question asked by Magaly.Clement on Nov 23, 2016
Latest reply on Nov 23, 2016 by Dan_Patterson

Hi!

 

This script works fine :

import time
from datetime import datetime

date_string = '2009-11-29 03:17 PM'
format = '%Y-%m-%d %I:%M %p'
format2 = '%m/%d/%Y %I:%M:%S %p'
my_date = datetime.strptime(date_string, format)
print my_date.strftime(format2)

Result :

11/29/2009 03:17:00 PM

But If I have "import arcpy", it doesn't work !!

import arcpy
import time
from datetime import datetime

date_string = '2009-11-29 03:17 PM'
format = '%Y-%m-%d %I:%M %p'
format2 = '%m/%d/%Y %I:%M:%S %p'
my_date = datetime.strptime(date_string, format)
print my_date.strftime(format2)

Result:

Traceback (most recent call last):
  File "E:\Scripts\1-Scripts\tests\ampm.py", line 40, in <module>
    my_date = datetime.strptime(date_string, format)
  File "C:\Python27\ArcGIS10.2\lib\_strptime.py", line 328, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: PM

 

My script needs arcpy, how to do the stuff without error ?

Thanks for help !

Outcomes