Shefali
Shefali

Reputation: 19

Change date format in order to find difference in Time in Neo4j 3.2.5

I am working on a code in Neo4j and want to find out the difference between two time columns. The date time is in format 20130508 19:14:56.913. I also tried using APOC function, but I am getting the error that it is Unknown function. Could anyone please help me this.

Upvotes: 0

Views: 1598

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16365

I think you can use the APOC function apoc.date.parse. The function signature is:

apoc.date.parse(date, targetTimeUnit, format)

date should be a string representing the date you are converting to the specified targetTimeUnit (ms for target milliseconds, in the example). The date should be in the specified format, indicated by the third parameter.

Take a look in this example:

WITH apoc.date.parse('20130508 19:14:56.913','ms','yyyyMMdd HH:mm:ss.ms') AS initialTime,
    apoc.date.parse('20130508 20:14:56.913','ms','yyyyMMdd HH:mm:ss.ms') AS finalTime
RETURN finalTime - initialTime as difference

The output will be:

╒════════════╕
│"difference"│
╞════════════╡
│3600000     │
└────────────┘

That is: a difference of 3600000 milliseconds between the two dates.

Upvotes: 1

Related Questions