Is it possible to compute period between two dates in Neo4J? I cannot find a query. I tried using duration function but it is showing an error.
This is what I used-
MATCH (c:Company)
WITH c.incorporation() AS start
WITH start,c.dissolution AS end
RETURN duration.between(start,end) AS Period
What error do you see? Double check that the properties in question really contain a time interval.
For calculating deltas see this example:
with date("2019-05-01") as from, date("2019-04-01") as to
return duration.between(to, from).months, duration.inDays(to, from).days, duration.inSeconds(to, from).seconds
How can I execute a cypher query for a list of dates at the same time?
Can you please provide more context and some sample data?
I have two columns - one is incorporation date for companies and the other one is dissolution date for companies. Now I want to compute period of operation for all the companies in Neo4J.
So the intersection time interval when all the companies were alive?
Sorry I did not get you..
I think we have, per row, what amounts to the start date and the end date for a company. This should just be a matter of using duration.between()
and/or duration.inDays()
providing the relevant dates, just as in Stefan's earlier example.
Can you provide the query you're using so far?
I am using this now: MATCH (c:Company)
WHERE c.dissolution <> "NA"
WITH c,apoc.date.format(apoc.date.parse(c.dissolution, 'ms', 'yyyy-MM-dd'), 'ms', 'MM-dd-yyyy') as Dislv,
apoc.date.format(apoc.date.parse(c.incorporation, 'ms', 'yyyy-MM-dd'), 'ms', 'MM-dd-yyyy') as Incorp
WITH c, [x IN split(Incorp, "-") | toInteger(x)] AS Inc, [x1 IN split(Dislv, "-") | toInteger(x1) ] AS Dis
WITH c,duration.inMonths (date({month: Inc[0], day: Inc[1], year: Inc[2]}), date({month: Dis[0], day: Dis[1], year: Dis[2]})) as Dur
WHERE c.dissolution>="2007" AND c.dissolution<="2015"
RETURN c.name,c.dissolution,toInteger(apoc.text.format("%02d", [Dur.months])) AS value
ORDER BY value DESC