Comparing dates in cypher


(Mail2michaelennis) #1

What is the BEST practice to compare two dates in CYPHER? I use the cypher timestamp() but I need to compare it to a parameter date in the format: moment().startOf('week').toDate().

(M. David Allen) #2

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.

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()

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.

(Mail2michaelennis) #3

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.