cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Unable to calculate difference between dates

info6
Node Link

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

3 REPLIES 3

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!

info6
Node Link

Hi ljubica.lazarevic

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

Kind regards