How to calculate difference between time fields over a table

386
1
07-31-2017 03:13 PM
SimonWebster1
New Contributor

I'm hoping someone might be able to help me here:

I am looking to calculate the difference between the timestamps in the current row of a table, and the preceding row. Then, if the difference exceeds a set amount, increment the number in the Journey_Number column by 1. At the moment I am dumping all my data to excel to do this, but it's very inefficient. Example data is below.

At the moment I've worked out a model that can draw in related files, spit each out as a shapefile, then merge the shapefiles, reduce identical values, and sort by the timestamp field using regular toolbox items. In theory the data should be sorted at this point so that it's all sequential. This function, however, requires something more specific such as a python script - and I'm in over my head. 

Any help is appreciated

(Given information)(Calculated Information)(Calculated Information)
TimestampSeconds_from_prior_line_to_this_lineJourney_Number
2015-07-13T23:49:09Z1
2015-07-13T23:49:17Z81
2015-07-13T23:49:23Z61
2015-07-13T23:49:24Z11
2015-07-13T23:49:32Z81
2015-07-13T23:49:44Z121
2015-07-13T23:49:51Z71
2015-07-13T23:49:59Z81
2015-07-17T06:04:27Z8682
2015-07-17T06:05:02Z352
2015-07-17T06:05:05Z32
0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

I assume it is the look-ahead portion and not time comparison portion that has you stumped.  For the look-ahead portion, there have been several recent questions/discussions on the topic although the issue being solved was different than time.  Two of those discussions that come to mind are:

Since a Python cursor is simply an iterable, you can do some basic internet searches on "Python look ahead iterable" and find several examples that can translate over to ArcPy cursors.

0 Kudos