Need to calculate time between rows with a date field

779
2
10-18-2010 05:07 PM
DavidEckley
New Contributor
I have a feature class with a date field.  Using the search cursor I want to be able to read one row of the feature class at a time and calculate the time between date field in each subsequent row and store the value in a separate list or dictionary.  What is the best way to do this?  Can I calculate the time difference in varying temporal units, i.e. days/hours/minutes?
0 Kudos
2 Replies
KimOllivier
Occasional Contributor III
The easiest way is to use the existing [ARCINFO Licence] ArcTool CalculateEndTime which moves the next rows datetime to the previous row. Then you can use simple subtraction to get the difference. If you look up the python datatype for datetime you can see that you can show the interval in any units.

If you have not got an ArcInfo licence, then a short python script would get around this meanness.
Read the dates in in sort order with a key and put in a dictionary. Then write out the dates using the dictionary as a lookup.
0 Kudos
DavidEckley
New Contributor
Thanks, Kim.  This was a simple fix!
0 Kudos