0

I am using apoc to calculate difference between two dates. It works when I supply value for N.ID in the MATCH clause. But it fails when I remove N.ID because I am trying to process the code for a bunch of IDs not a single one.

MATCH (N:PERSON)-[M:PLACED]-(K:ORDER) WHERE  K.ORDER_CODE="A23"  and N.ID=2511217
WITH N ,max(apoc.date.parse(SUBSTRING(M.ORDER_DATE,0,8),'d',"yyyymmdd")) AS initialTime,
apoc.date.parse(SUBSTRING(N.charge_DATE,0,8),'d',"yyyymmdd") AS finalTime
RETURN N.ID, finalTime - initialTime as difference ;

N.ID difference
2511217 4

However, when N.ID is removed, I get:

MATCH (N:PERSON)-[M:PLACED]-(K:ORDER) WHERE  K.ORDER_CODE="A23"    
WITH N ,max(apoc.date.parse(SUBSTRING(M.ORDER_DATE,0,8),'d',"yyyymmdd")) AS initialTime,
apoc.date.parse(SUBSTRING(N.charge_DATE,0,8),'d',"yyyymmdd") AS finalTime
RETURN N.ID, finalTime - initialTime as difference ;

Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke function apoc.date.parse: Caused by: java.text.ParseException: Unparseable date: "NULL"

CKE
  • 1,533
  • 19
  • 18
  • 29

2 Answers2

0

I think its due to the aggregation function max. Can you try with this query :

MATCH (N:PERSON)-[M:PLACED]-(K:ORDER) WHERE  K.ORDER_CODE="A23"
WITH 
    N ,
    apoc.date.parse(SUBSTRING(M.ORDER_DATE,0,8),'d',"yyyymmdd") AS initialTime,
    apoc.date.parse(SUBSTRING(N.charge_DATE,0,8),'d',"yyyymmdd") AS finalTime
WITH N, max(initialTime) AS initialTime, finalTime
RETURN N.ID, finalTime - initialTime as difference ;
logisima
  • 7,340
  • 1
  • 18
  • 31
  • I still get the same error - with or without MAX. When I qualify the 'Where' clause with a specific ID it works, but fails when that's removed. – AlabamaRaider Jun 29 '18 at 17:19
0

It looks like there are multiple PERSON nodes placing the same ORDER, but some of them lack the charge_DATE property needed by your query.

cybersam
  • 63,203
  • 6
  • 53
  • 76