I would like to modify the following accumulative/sequential python code sample in field calculator in a Date Time field. I think this is the correct code to use but let me know if not. The Date Time field is formatted like so: 30/01/2015 18:30:00. I need to add increments of 162 seconds to the time portion of the value for 24 records. The date will not change.

Here is the code sample copied from http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000004s000000 and I've put my field name 'Date_Time) in



Expression Type:


Code Block:

total = 0
def accumulate(increment):
    global total
    if total:
        total += increment
        total = increment
    return total

I know that I can change a single row's Date_Time value once by running this syntax in field calculator: DateAdd ("s", 162, [Date_Time] ) but I need to loop through the values in the Date_Time column starting with 30/01/2015 18:30:00 for the first row and adding 162 seconds to the new total each time.

  • You can use simple expression, no code Dateserial(2015,01,30)+18.5/24+162* [FID]/24/60/60
    – FelixIP
    Commented Feb 2, 2015 at 2:53

1 Answer 1


The way I just did this assumes that you are using a file geodatabase features class, with an OBJECTID field that starts at 1.

I've called my date field DateField so change that for yours.

Parser: Python

Code Block:

def inc162secs(oid):
    startDataObj = datetime.datetime.strptime("30/01/2015 18:30:00", "%d/%m/%Y %H:%M:%S")
    return startDataObj + datetime.timedelta(seconds=( (oid - 1) * 162))

DateField =

inc162secs( !OBJECTID! )

The result was:

enter image description here

  • Thank you PolyGeo!!! Amazingly fast and completely satisfactory reply - your answer was exactly what I was looking for! I just applied it and !BAM! perfect results. Commented Feb 2, 2015 at 3:24
  • By coincidence I wrote a similar example into one of my eLearning videos this morning so I had the answer at my fingertips.
    – PolyGeo
    Commented Feb 2, 2015 at 3:27

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.