15

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

Kanak
  • 301
  • 2
  • 3
  • 9

1 Answers1

21

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;
Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • 2
    **UPDATE** We now support numeric range indexes, so it's possible to now make this query super fast. Also, check out APOC date/time functions: https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_date_time_support – Ryan Boyd Jan 16 '17 at 22:58