# Time Duration between subsequent rows

How would you calculate the duration between subsequent rows.

Suppose I have `Match (j)-[r]->(m) return r.timestamp order by r.timestamp` and I want to find the duration between each subsequent row:

"2019-03-16T00:01:55.698000000Z"
"2019-03-16T00:05:34Z"
"2019-03-16T00:05:53Z"
"2019-03-16T00:12:03.887000000Z"
"2019-03-16T00:12:34.684000000Z"
"2019-03-16T00:13:27.740000000Z"
"2019-03-16T00:14:34.119000000Z"
"2019-03-16T00:14:40Z"
"2019-03-16T00:17:46.631000000Z"
"2019-03-16T00:18:06.872000000Z"
"2019-03-16T00:19:52Z"
"2019-03-16T00:32:28Z"
"2019-03-16T00:33:05.154000000Z"
"2019-03-16T00:38:42Z"
"2019-03-16T00:38:50Z"
"2019-03-16T00:39:12Z"
"2019-03-16T00:46:29Z"
"2019-03-16T00:47:30Z"
"2019-03-16T00:49:38Z"
"2019-03-16T00:52:05Z"
"2019-03-16T00:54:20.804000000Z"
"2019-03-16T00:54:24Z"
"2019-03-16T00:54:38.405000000Z"
"2019-03-16T00:56:01Z"
"2019-03-16T00:57:29Z"
"2019-03-16T00:57:38Z"
"2019-03-16T00:58:46Z"
"2019-03-16T01:00:08Z"
"2019-03-16T01:00:31Z"
"2019-03-16T01:00:35Z"
"2019-03-16T01:03:26.288000000Z"
"2019-03-16T01:09:21.360000000Z"
"2019-03-16T01:11:03Z"
"2019-03-16T01:19:38Z"
"2019-03-16T01:22:24.983000000Z"
"2019-03-16T01:22:46Z"
"2019-03-16T01:24:46Z"
"2019-03-16T01:33:13Z"
"2019-03-16T01:34:42Z"
"2019-03-16T01:36:20Z"
"2019-03-16T01:41:29Z"
"2019-03-16T01:47:13Z"
"2019-03-16T01:48:41Z"
"2019-03-16T01:52:28.072000000Z"
"2019-03-16T01:54:35Z"
"2019-03-16T02:00:26Z"
"2019-03-16T02:03:31Z"
"2019-03-16T02:05:34Z"
"2019-03-16T02:07:12.520000000Z"
"2019-03-16T02:07:13Z"
"2019-03-16T02:07:38.564000000Z"
"2019-03-16T02:10:00Z"
"2019-03-16T02:11:33Z"
"2019-03-16T02:14:17Z"
"2019-03-16T02:15:23Z"
"2019-03-16T02:15:52Z"
"2019-03-16T02:19:18Z"
"2019-03-16T02:21:28Z"
"2019-03-16T02:24:11Z"
"2019-03-16T02:25:38Z"
"2019-03-16T02:27:14Z"
"2019-03-16T02:27:20Z"
"2019-03-16T02:27:38.303000000Z"
"2019-03-16T02:29:48Z"
"2019-03-16T02:37:50.307000000Z"
"2019-03-16T02:44:25Z"
"2019-03-16T02:44:57Z"
"2019-03-16T02:47:39Z"
"2019-03-16T02:51:12Z"
"2019-03-16T02:51:13Z"
"2019-03-16T02:55:20Z"
"2019-03-16T03:01:26Z"
"2019-03-16T03:01:49Z"
"2019-03-16T03:01:56Z"
"2019-03-16T03:08:07.958000000Z"
"2019-03-16T03:17:36Z"
"2019-03-16T03:25:08Z"
"2019-03-16T03:34:08Z"
"2019-03-16T03:40:14Z"
"2019-03-16T03:42:37Z"
"2019-03-16T03:45:38Z"
"2019-03-16T03:58:09Z"
"2019-03-16T04:00:20Z"
"2019-03-16T04:02:57Z"
"2019-03-16T04:09:00Z"
"2019-03-16T04:09:56Z"
"2019-03-16T04:10:43Z"
"2019-03-16T04:22:53.325000000Z"
"2019-03-16T04:25:23Z"
"2019-03-16T04:31:03Z"
"2019-03-16T04:35:06Z"
"2019-03-16T04:36:29Z"
"2019-03-16T04:39:22Z"
"2019-03-16T04:40:20Z"
"2019-03-16T04:40:33.835000000Z"
"2019-03-16T04:40:41Z"
"2019-03-16T04:41:04Z"
"2019-03-16T05:07:30Z"
"2019-03-16T05:11:47.778000000Z"
"2019-03-16T05:15:39Z"

would return
duration value (row[i],row[i+1])

Can this be done in Cypher?

Found the answer here with doing apoc.coll.pairsMin: https://stackoverflow.com/questions/41007289/how-do-i-calculate-the-difference-between-and-percentile-of-properties

Solution:
`match (j)-[r]->(m) with COLLECT(r.timestamp) AS obs with apoc.coll.pairsMin(obs) as pairs UNWIND pairs AS pair_obs with pair_obs[0] as obs1, pair_obs[1] as obs2 return duration.between(obs1,obs2) limit 100`