I have a point feature class in ArcGIS desktop. There is a timestamp column named
TS in datetime format in the attribute table.
I need to calculate and write time differences of rows from previous rows to a new column named
RowDiff. Results will be in "seconds".
RowDiff datatype is short integer.
I've found these links but I have no idea about implementing the functions:
I've found the following code but results are in string format like
0:00:06.00005 and useless for me. What I need is row differences in seconds and an integer data type, not decimals.
import arcpy from arcpy import da gpsdata = arcpy.GetParameterAsText(0) #set firstRow variable to true firstRow = True with arcpy.da.UpdateCursor(gpsdata, ["OBJECTID", "TS", "D_T"]) as cursor: for row in cursor: gap2 = row #check if its the first row if firstRow == True: gap1 = gap2 #set firstrow to false firstRow = False continue row = str(gap2 - gap1) gap1 = gap2 cursor.updateRow(row)
Sample results should be as follows: