I need to calculate a date field of a FGDB raster catalog (but I guess it could be any table or fc for that matter). The field I need to convert is a string that contains date values in the format: '2013-09-23 10:01:50' or for your Python referenced format it is: '%Y-%m-%d %H:%M:%S'
My problem is that (I think) the ESRI Date field has trouble with really early dates. For example, this how could I correctly set a date field value with this string:
'0001-01-01 00:00:00'
Yes, that is year "1". When I run the code below, it calculates the field but this example value above is set to '1/1/2001', dropping the hh:mm:ss and always starts in the 21st century. I need the date field to save it as the original string, but stored as a date --- I am using the Time Slider to create time-series animations and it is very finicky about using dates.
Any help is appreciated!
My problem is that (I think) the ESRI Date field has trouble with really early dates. For example, this how could I correctly set a date field value with this string:
'0001-01-01 00:00:00'
Yes, that is year "1". When I run the code below, it calculates the field but this example value above is set to '1/1/2001', dropping the hh:mm:ss and always starts in the 21st century. I need the date field to save it as the original string, but stored as a date --- I am using the Time Slider to create time-series animations and it is very finicky about using dates.
Any help is appreciated!
Code:
fld = "_dateText_str"
updFld = "_dateText_str_Converted"
cursor = arcpy.UpdateCursor(ras)
for row in cursor:
strVal = row._dateText_str
dtVal = datetime.datetime.strptime(strVal, '%Y-%m-%d %H:%M:%S')
row.setValue(updFld, dtVal)
cursor.updateRow(row)