Neo4j Cypher比较Cypher查询中的日期 [英] Neo4j Cypher comparing dates in Cypher query

查看:752
本文介绍了Neo4j Cypher比较Cypher查询中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在设计一个带有Neo4j数据库的系统,在该系统中,我必须能够进行查询以检查节点中的Date属性是在提供的Date之前,之前还是之后.

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.

我应该如何在Neo4j Node属性中存储Date以便能够与Cypher查询进行比较,例如基于简单的运算符,例如==><

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 ==, >, <

可以像Long timestamp一样存储Date吗?这样行吗?如果否,请提出一个更好的决定.

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

已更新

我没有运气尝试过的查询:

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

filterValue153.valuejava.util.Date对象一样存储在Value.value节点属性中的位置

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

已更新

此查询工作正常

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) 

但是如何处理格林尼治标准时间1970年1月1日00:00:00之前的日期? 还可以在此Cypher查询中在日期上应用=><操作吗?

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 ?

推荐答案

相关问题:

但是,该问题可以追溯到2012年.从那时起,我们的APOC就支持 SimpleDateFormat类的Javadoc .

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.

1970年1月1日之前的日期将起作用,它们将简单地用负数.例如:

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.

这篇关于Neo4j Cypher比较Cypher查询中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆