Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-14-2020 07:10 AM
Hi, all.
I am trying to calculate the duration between two connected nodes and place it on the relationship
This duration is calculated in seconds and is converted to an integer.
E.g..
node:
ID | eventtime |
---|---|
1 | 2020/2/10 10:00:00 |
2 | 2020/2/10 10:00:12 |
3 | 2020/2/10 11:00:12 |
Relation:
from_ID | to_ID | duration |
---|---|---|
1 | 2 | 12 |
2 | 3 | 3600 |
Thanks.
Solved! Go to Solution.
03-15-2020 12:56 AM
Yes you can do.Suppose you have two nodes with node1. eventime = date1 and node2.eventtime = date2
WITH apoc.date.parse(node1.eventtime,'s','yyyy/MM/dd HH:mm:ss') AS initialTime,
apoc.date.parse(node2.eventtime,'s','yyyy/MM/dd HH:mm:ss') AS finalTime
RETURN finalTime - initialTime as difference.
03-14-2020 10:43 AM
Relationship is already there between the nodes?
Change the eventtime into Datetime and apply duration.inseconds(eventtime1,eventtime2).seconds
03-14-2020 11:30 PM
Hi,
Relationship is already there between the node.
Is there any way to convert the format on Neo4j?
From '2020/02/10 10:00:00' to '2020-02-10T10:00:00Z'
Thanks for your reply.
03-14-2020 07:31 PM
Here is a solution.
WITH apoc.date.parse('2020/2/10 10:00:00','s','yyyy/MM/dd HH:mm:ss') AS initialTime,
apoc.date.parse('2020/2/10 10:00:12','s','yyyy/MM/dd HH:mm:ss') AS finalTime
RETURN finalTime - initialTime as difference
result: 12 seconds
WITH apoc.date.parse('2020/2/10 10:00:12','s','yyyy/MM/dd HH:mm:ss') AS initialTime,
apoc.date.parse('2020/2/10 11:00:12','s','yyyy/MM/dd HH:mm:ss') AS finalTime
RETURN finalTime - initialTime as difference
result: 3600 seconds
03-14-2020 11:31 PM
Hi,
Is there a way to handle all the data?
No specific time required like '2020/2/10 10:00:00'?
Thanks for your reply.
03-15-2020 12:56 AM
Yes you can do.Suppose you have two nodes with node1. eventime = date1 and node2.eventtime = date2
WITH apoc.date.parse(node1.eventtime,'s','yyyy/MM/dd HH:mm:ss') AS initialTime,
apoc.date.parse(node2.eventtime,'s','yyyy/MM/dd HH:mm:ss') AS finalTime
RETURN finalTime - initialTime as difference.
All the sessions of the conference are now available online