0

I have column that contains dates that are created from a numpy array to fc, since numpy doesn't handle date types I have had to create another field to update the rows. When using this script in the ArcPy window, no errors are returned, however my values do not change for UPDATE_DATE_DATE. What could cause this?

UPDATE_DATE_DATE is a DATE type field while OPEN_TIME is a string type field. And I would like to set the string values as DATE type in UPDATE_DATE_DATE.

Here is an example of the date format for OPEN_TIME, 9/25/2015 12:29:04 AM.

cursor = arcpy.UpdateCursor(fc)
for row in cursor:
    row.setValue("UPDATE_DATE_DATE", row.getValue("OPEN_TIME"))
cursor.updateRow(row)
3
  • 4
    Can you provide some examples of your dates? There are many date formats. Oct 8, 2015 at 19:10
  • 5
    Following @EmilBrundage 's comment, the cursor.updateRow(row) command appears to be out-of-loop, like it may only execute on the last row.
    – Jim
    Oct 8, 2015 at 19:56
  • @Jim I think you should create an answer from your comment. It will only need to be expanded a little. I just fell for a similar trap of forgetting to include an updateRow and seeing no change to my data.
    – PolyGeo
    Jun 22, 2016 at 0:10

1 Answer 1

1

The call to the cursor.updateRow(row) method appears to be out-of-loop in the code snippet provided. Given the code snippet, I'm thinking cursor.updateRow(row) would only execute once, after exiting the for loop. Indenting the cursor.updateRow(row) as follows should fix it:

cursor = arcpy.UpdateCursor(fc)
for row in cursor:
    row.setValue("UPDATE_DATE_DATE", row.getValue("OPEN_TIME"))
    cursor.updateRow(row) # Indent added here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.