Neo4j Cypher comparing dates in Cypher query

好久不见. 提交于 2019-12-24 07:56:37

问题


Right now I'm designing a system with Neo4j database where I have to be able to have a query check if a Date property in a node is before, equal or after the provided Date.

How should I store the Date inside of Neo4j Node property to be able to do a comparison with Cypher query based for example on simple operators like ==, >, <

Is it okay to store Date like Long timestamp? Will it work this way ? If no, please suggest a better decision.

UPDATED

Queries I have tried with no luck:

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId}  MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE  (filterValue153.value = '60305027689736') 

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId}  MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE  (filterValue153.value = 'Mon Dec 27 22:35:56 EET 3880') 

Where filterValue153.value has been stored like java.util.Date object in Value.value node property

@NodeEntity
public class Value extends Authorable {

    public final static String NODE_NAME = "Value";

    private final static String SET_FOR = "SET_FOR";
    private final static String SET_ON = "SET_ON";

    @Relationship(type = SET_FOR, direction = Relationship.OUTGOING)
    private Decision decision;

    @Relationship(type = SET_ON, direction = Relationship.OUTGOING)
    private Characteristic characteristic;

    private Object value;

...

}

at database level for Value node I have a following data:

id: 848013
value:  1482873001556

UPDATED

This query works fine

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId}  MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE  (filterValue153.value = 60305030539682) 

but how to deal with dates prior January 1, 1970, 00:00:00 GMT ? Also is it okay to apply =, >, < operations in this Cypher query on dates ?


回答1:


Related question:

  • Compare dates with Spring Data neo4j

However, that question dates back to 2012. Since then, we have APOC with support for date/time conversion. This lets you convert date/time values in formats described in the Javadoc of the SimpleDateFormat class.

Dates before 1970/01/01 will work, they will be simply represented with negative numbers. For example:

CALL apoc.date.parseDefault('1969-07-21 02:56:15', 's')
YIELD value 

Arithmetic comparison operators (=, <>, <, ...) will work on timestamps.



来源:https://stackoverflow.com/questions/41351012/neo4j-cypher-comparing-dates-in-cypher-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!