0

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.

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
Shefali
  • 19
  • 3

1 Answers1

1

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.

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
  • I tried this, I got this error: Unknown function 'apoc.date.parse' – Shefali Oct 09 '17 at 12:02
  • @Shefali so you have a problem in your APOC installation. – Bruno Peres Oct 09 '17 at 12:04
  • How should APOC be installed? – Shefali Oct 09 '17 at 12:43
  • @Shefali you can found installation instructions in [this link](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_installation). Basically you need download the jar file and put it into the Neo4j's `/plugins` directory. Remember to install APOC procedures according the version of Neo4j you are using. Take a look in the version compatibility matrix in the link. – Bruno Peres Oct 09 '17 at 12:49