Riegel
Riegel

Reputation: 21

Calculate in a query the difference in minutes between a start time and an end time

I am new in the Neo4j community. So I have the following question: How can I calculate in a query the difference in minutes between the two properties "start time" and "end time" (both are of the datatype DateTime)? Thanks

Upvotes: 0

Views: 1314

Answers (2)

mastisa
mastisa

Reputation: 2083

Based on neo4j docs

A Duration represents a temporal amount, capturing the difference in time between two instants.

Example cypher:

RETURN duration.inSeconds(localdatetime('2015185T19:32:24') ,localdatetime('2015185T19:39:24')).minutes, duration.inSeconds(localdatetime('2015185T19:32:24') ,localdatetime('2015185T19:39:24'))

Output:

enter image description here

Upvotes: 0

logisima
logisima

Reputation: 7478

What you want to do is to calculate a Duration between two DateTime.

To do this, the duration in Neo4j comes with thefunction duration.inSeconds that will give you a time duration. Then you can have the number of minutes just by calling .minutes.

This is an example :

WITH datetime() AS now, datetime('2017-09-17T12:50:35.556+0100') AS date
RETURN duration.inSeconds(date, now).minutes

Cheers

Upvotes: 2

Related Questions