Hi,
I want to convert some date strings into correct dates, to be recognized by Python and ArcGIS.
Setup:
ArcGIS 10.2.1
Python 2.7.5
All data are located within a FGDB...
I set the workspace to be the FGDB, created a new Field of type data in my table and went on with the following things within the IDLE Shell
import datetime
with arcpy.da.UpdateCursor(myTable, [field01, field02]) as UCursor:
for row in UCursor:
origDate = datetime.datetime.strptime(row[0], '%d%b%Y')
row[1] = datetime.date.strftime(origDate, '%Y-%m-%d')
UCursor.updateRow(row)
Things work fine until the input string is '11MAY2004', where I get the following error message:
Traceback (most recent call last):
File "<pyshell#9>", line 4, in <module>
origDate = datetime.datetime.strptime(row[0], '%d%b%Y')
File "C:\Python27\ArcGISx6410.2\lib\_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '11MAY2004' does not match format '%d%b%Y'
I did try the whole thing in plain Python (same shell) before, where I simply did:
orig = '11MAY2004'
x = datetime.datetime.strptime(orig, '%d%b%Y')
and this works without any problem!!!
Can somebody enlighten me where I go wrong?
Cheers, Thomas