Select to view content in your preferred language

Need to calculate time between rows with a date field

1015
2
10-18-2010 05:07 PM
DavidEckley
Emerging 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
Honored Contributor
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
Emerging Contributor
Thanks, Kim.  This was a simple fix!
0 Kudos