Neo4j Cypher比较Cypher查询中的日期 [英] Neo4j Cypher comparing dates in Cypher query
问题描述
现在,我正在设计一个带有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.value
像java.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 已更新 此查询工作正常 但是如何处理格林尼治标准时间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 相关问题: 但是,该问题可以追溯到2012年.从那时起,我们的APOC就支持 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 1970年1月1日之前的日期将起作用,它们将简单地用负数.例如: Dates before 1970/01/01 will work, they will be simply represented with negative numbers. For example: 算术比较运算符( Arithmetic comparison operators ( 这篇关于Neo4j Cypher比较Cypher查询中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!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)
=
,>
,<
操作吗?=
, >
, <
operations in this Cypher query on dates ?推荐答案
SimpleDateFormat
类的Javadoc .SimpleDateFormat
class.CALL apoc.date.parseDefault('1969-07-21 02:56:15', 's')
YIELD value
=
,<>
,<
,...)将在时间戳上起作用.=
, <>
, <
, ...) will work on timestamps.