Unable to calculate difference between dates

Hi

I am trying to subtract two dates, but am running into what I think are data type issues.

When I use the following statement:

RETURN apoc.date.convert(endDate - LAST_DATE, "ms", "d")

the following error is returned:

Neo.ClientError.Statement.TypeError: Cannot subtract Date from Long

The data types for each are:

apoc.meta.type(endDate) apoc.meta.type(LAST_DATE)
"INTEGER" "LocalDate"

endDate was created from a string:

date('2012-06-12) AS endDate

LAST_DATE was created:

WITH apoc.date.parse('12/31/2018', 'y', 'MM/dd/yyyy') AS LAST_DATE

I haven't been able to either convert endDate using apoc.date.parse to INTEGER, or use toInteger().

I appreciate any help anyone could give.

Kind regards

Hi!

You will need to use the duration keyword to help with that. For example, if I wanted to know the number of days between 2012-04-04 and 2011-04-05, I'd write something like this:

return duration.inDays(date("2012-04-04"), date("2011-04-05")).days

I hope that helps!

Hi ljubica.lazarevic

Thanks so much ! With a bit of tweaking I got my Cypher working with your help - very happy!

Kind regards

for those needing more details of the Neo4j temporal functions see https://neo4j.com/docs/cypher-manual/3.5/functions/temporal/duration/#functions-duration-indays