My objective is to change the values under field "DATE_IMPOR" which are currently set at to the current time using time.localtime function. I'm having some problems getting there, above all one line appears to be most problematic "row.setValue("DATE_IMPOR", new_time)".

The field data type of "DATE_IMPOR" is Date, therefore it has to be Date format such as YYYY or YYYY/MM/DD or types supported.

In short, what I get is a Runtime Error.

Here is my script so far:

import arcpy
import time

#environnement de travail
arcpy.env.workspace = "D:/M1 Geomatique/Programmation II/Dossier"

cursor = arcpy.UpdateCursor("ZONE_INONDATION_SYNTHESE_67.shp", "DATE_IMPOR")

#Update cursor
    for row in cursor:
        new_time = time.localtime()[0]
        row.setValue("DATE_IMPOR", new_time)


*One note: I wasn't sure where it would be better to ask this question, therefore I have placed it here as well. Apologises for that.

  • time.localtime()[0] will give you int - 2015, not Date. Did you try a simple new_time = time.localtime() ? Commented Apr 16, 2015 at 9:29
  • 1
    try this line: new_time = time.strftime('%Y/%m/%d')
    – EikeMike
    Commented Apr 16, 2015 at 10:57
  • Pankevicius, I tried it and unfortunately it gives me an error.
    – Geosphere
    Commented Apr 27, 2015 at 8:36
  • Mike, I get the same runtime error as before.
    – Geosphere
    Commented Apr 27, 2015 at 8:40

1 Answer 1


Eventually, I managed to find a solution.

Firstly, I changed the way the for loop was being done, making a condition with if so that row.DATE_IMPOR knows what to look for, in this case it was which I passed it in as (None).

e.g. if row.DATE_IMPOR == None: row.DATE_IMPOR = time.strftime('%d/%m/%Y') cursor.updateRow(row)

However, I did not used localtime() as I realized that I would have needed another loop to get the data into proper format, as time.localtime() gives you tuples.

This way was much shorter, effective, and safer if you think about it.

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.