Storing current day, month, year as properties in a relation in neo4j using cypher query

1.1k Views Asked by At

I want to create a relationship in neo4j having properties as day, time, year of the current date.

how can I get the current day,month, year using cypher neo4j??

2

There are 2 best solutions below

0
On

First, Neo4j doesn't have support for DateTime type.

data

CREATE (n1:Node)-[r:RELATIONSHIP {day: 30, month: 9, year: 2015}]->(n2:Node)

read

MATCH (:Node)-[r:RELATIONSHIP]->(:Node)
RETURN r.day, r.month, r.year

Another approach could be use GraphAware TimeTree. Which is Neo4j module for representing time in Neo4j as a tree structure.

0
On

I think you can simply store a timestamp, and then deal with it in your application:

CREATE (n1:Node)-[r:RELATIONSHIP {date:timestamp()}]->(n2:Node)

As you can see on Neo4j's documentation, cypher does actually support timestamp() method call in the query, which is the most accurate date you can store, as a long