Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get current time using cypher

Tags:

neo4j

cypher

lets say for example, I have ten nodes with a name and time property. i have used the timestamp() function but it returns a value, that is the difference between the current time and the 1st of january, 1970 in milliseconds. What i want to know is, is there a function or possiblitiy to get the current time. if its there, can i get a sample code on how we can use it as an attribute in a node. also do tell me if its possible to extract data from the node that was updated a few hours ago using timestamp function itself

like image 819
Kanak Avatar asked Dec 12 '13 09:12

Kanak


People also ask

Does Neo4j support DateTime?

Contents. Cypher provides functions allowing for the creation and manipulation of values for each temporal type — Date, Time, LocalTime, DateTime, and LocalDateTime.

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.

Is order by a valid Cypher clause?

You can order by multiple properties by stating each variable in the ORDER BY clause. Cypher will sort the result by the first variable listed, and for equals values, go to the next property in the ORDER BY clause, and so on. This returns the nodes, sorted first by their age, and then by their name.

What is a cypher statement?

Cypher is a declarative graph query language that allows for expressive and efficient data querying in a property graph. Cypher was largely an invention of Andrés Taylor while working for Neo4j, Inc. (formerly Neo Technology) in 2011.


1 Answers

Updated for 2018: There are now date types in Neo4j. You can use real date functions, and have them be range-lookup-friendly index-backed. :)

CREATE (:Node{dt:datetime()});

CREATE INDEX ON :Node(dt);

MATCH (n:Node)
WHERE n.dt > datetime('2018-06-24T12:50:35.556+0100')
RETURN n;

Updated for 2017 (thanks for comments): timestamp() returns a value for milliseconds. You can do subtraction with this, and calculate the number of milliseconds for "a few hours ago" to see if it is in range.

CREATE ({ts:timestamp});

MATCH (n)
WHERE n.ts > timestamp() - (1000*60*60*4) // 4 hours ago
RETURN n;
like image 194
Eve Freeman Avatar answered Sep 28 '22 02:09

Eve Freeman