Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-07-2019 09:43 AM
01-07-2019 12:48 PM
Have a look at the manual on temporal functions. Neo4j 3.4.x comes with a lot of date functions built into it. And in terms of straight comparison, you can just use <
, >
, and so on to compare them.
https://neo4j.com/docs/cypher-manual/current/functions/temporal/
If there's a particular type of comparison you're trying to do, let us know.
In the case of moment dates, if you're using javascript and you have an ISO formatted date string like:
> moment().startOf('week').toDate()
2019-01-06T05:00:00.000Z
Then you can feed that into neo4j's datetime
function and then use it as an instant and use all of the cypher functions linked above.
01-15-2019 03:02 PM
Thanks David. I wanted to store date as moment().format to later use it as a sort variable. I have some issues with getting my result sorted on time.....I think I will do it in Javascript.
08-19-2019 02:39 AM
Comparing dates in cypher does not seem straight-forward. The documentation (link cited above) mainly looks at declaration and conversion, but no comparisons.
i.e. the following and variations do not return any results (with 'timestamp' valid cypher datetime object)
MATCH (n) where n.timestamp >= date({year:2019,month:1}) RETURN n
MATCH (n) where n.timestamp <= datetime({year:2019,month:1}) RETURN n
Any help appreciated.
08-19-2019 06:08 AM
How you compare n.timestamp will depend upon how that value was set.
Perhaps you could do something like:
WITH datetime({year: 2019, month: 1, day: 1}).epochMillis AS testDate
// or
// WITH datetime({year: 2019, month: 1, day: 1}).epochSeconds AS testDate
MATCH (n) WHERE n.timestamp >= testDate RETURN n
Elaine
11-11-2020 06:12 AM
Hi guys,
Is there any difference in performance using something like this:
MATCH (n) WHERE n.timestamp >= datetime({year: 2019, month: 1, day: 1}).epochMillis RETURN n
Versus declaring the datetime in the beginning of the query, as @elaine.rosenberg suggested?
WITH datetime({year: 2019, month: 1, day: 1}).epochMillis AS testDate
MATCH (n) WHERE n.timestamp >= testDate RETURN n
Does Neo4j compute the function datetime() n times in the first case and only computes one time in the second case?
I ran a test in a query that has about 1M nodes and the second option was consistently 2 seconds faster (22s vs 20s).
All the sessions of the conference are now available online