How to fetch the data which is 2 hr old


(Tanmoymoulik) #1

Dear All,

I am new to neo4j.FOr my project I have uploaded the data in ne04j.I have added created_time and modified_time as 2 property of the node.Now i want to build cypher query which would pull old those data which are modified 2 hr before.Can you share sample scirpt which would be helpful for me to fetch the data.


(Paul Drangeid) #2

How did you store your dates? As date/time string, or did you use timestamp()? If you used timestamp, you could do something like this:
With (Timestamp()- 7200000) as newerthan
MATCH (n:label) where n.modified_time < newerthan
Return n

Couldn't test this, as I'm on my mobile right now


(Tanmoymoulik) #3

I had stored the date in timestamp format.Thanks for suggestion Let me test confirm.

Thanks


(Tanmoymoulik) #4

Hi Paul,

I did tried but it not working.Actually I had stored the time in datetime().So the above condition is not working.Can you suggest how can we fetch data which are last modified say 8 hr before from current time.


(Paul Drangeid) #5

With (Timestamp()- 28800000) as olderthan
MATCH (n:Mynode) where datetime(n.modifiedtime).epochmillis < olderthan
return n

This will return nodes that were modified MORE THAN 8 hours prior to right now.

You may find it more convenient to store your timestamps converted to epoch, which makes it easier/faster to perform compare operations on them in your where clauses


(Tanmoymoulik) #6

Thanks for the solution Paul.