Is there an Average Duration? If not can we put a request in for such a concept?

cypher

(Benjamin Squire) #1

I am trying to get the average duration between two time stamps and it appears Cypher cannot do this. Can we get a change request for future versions to include this?


(Benjamin Squire) #2

So I found this here: https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-avg-duration saying you can use avg on duration but when I run it on 3.49 I get the following error:

Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Float or Integer but was Duration (line 1, column 103 (offset: 102)) "Match (u:User) with u limit 100 with duration.between(u.first_obs,u.last_obs) as d return avg(d)" ^

My guess is this was not implemented until 3.5. I easy work around is to do some simple math to get the query to think of the data as a float:

Match (u:User) with u limit 100 with duration.between(u.first_obs,u.last_obs) as d return avg(d.days+tofloat(d.minutes)/1440)