1
votes

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

1 Answers

1
votes

Related question:

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.