Calculate duration in seconds and trans to converted to an integer

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.

@pawa19961996,

Relationship is already there between the nodes?
Change the eventtime into Datetime and apply duration.inseconds(eventtime1,eventtime2).seconds

1 Like
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

1 Like

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.

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.

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.

1 Like