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)
Solved! Go to Solution.
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!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)
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!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)
The File Geodatabase date field only supports dates from 12/31/1899 forward. I know this because the internal representation of the data is a number (exposed through the Summary Statistics tool). I know the internal representation of July 28, 2013 is 41483 days, which only allows 113 years back to day 0. The date field does not support negative numbers internally. I verified that the number of days between 12/31/1899 and 7/28/2013 is 41483 in Excel. So you will not be able to use an fgdb date field to do what you want.
This should be documented with the other field data type descriptions and limitations in the help, but it isn't.
If that's how you want to use the date field (not worrying about real date), add 2000 to each seems to be a easy solution. 🙂