Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-09-2019 03:50 AM
I want to match all the nodes between two date. At the moment every node in my db has this form
"id": *********,
"application": *****,
"message": ******,
"timestamp": *******
where timestamp has a form like this
"timestamp": "2019\09\04 11:01:33"
Is it possible match all node between a specific date or time like from 2019/09 to 2019/01 ?
thanks
09-09-2019 04:46 AM
yes except I think its not liking the format of the timestamp.
running
return datetime();
for example returns
2019-09-09T11:43:10.553000000Z"
further https://neo4j.com/docs/cypher-manual/3.5/syntax/temporal/#cypher-temporal-specify-date indicates
If the year is before 0000 or after 9999, the following additional rules apply:
- must prefix any year before 0000
+ must prefix any year after 9999
The year must be separated from the next component with the following characters:
- if the next component is month or day of the year
Either - or W if the next component is week of the year
Q if the next component is quarter of the year
If the year component is prefixed with either - or +, and is separated from the next componen
So using /
as the delimiter within the date component is not allowed
in the end provided you get the correct format you should then be able to run
match(n:MyNode)
where date(datetime(n:timestamp_prop))='2019-09-04' or
date(datetime(n:timestamp_prop))< 12019-09-05`;
09-09-2019 06:37 AM
thanks for your answer.
I have modified the timestamp. Now it's like this
"time": "2019-09-04T11:01:33+0000"
but when I execute the query
match(n:MyNode)
where date(datetime(n:timestamp))='2019-09-04' or
date(datetime(n:timestamp))< 2019-09-05`
return n
I get this error
SyntaxError: invalid literal number (line 3, column 35 (offset: 100)) "date(datetime(n:timestamp))< 2019-09-05"
09-09-2019 06:52 AM
maybe this is an error in formatting but line 3 appears to be
date(datetime(n:timestamp))< 2019-09-05`
when it should be
date(datetime(n:timestamp))< '2019-09-05'
09-09-2019 06:56 AM
I have already tried also this solution ( because ` it seems stranger to me), but I get another error. I get
Type mismatch: expected Date but was String
09-09-2019 07:30 AM
how did you created the node. Can you return the contents of the node?
09-09-2019 07:35 AM
To create every node, I use the Facebook Graph api to take every post. In particular I used this code in Python to connect with neo4j db and to create my nodes
allPosts = [ ]
class Post:
def __init__(self, id, message, time, application):
self.id = id
self.message = message
self.time = time
self.application = application
def __repr__(self):
return '<Event object ({} {} {} {})>'.format(self.id, self.message, self.time, self.application)
def __str__(self):
return '{} {} {} {}'.format(self.id, self.message, self.time, self.application)
def takePosts(postNum):
profile = fbgraph.get_object("me")
posts = fbgraph.get_connections(profile["id"], "posts")
i = 0
while True:
try:
for post in posts["data"]:
if i == int(postNum):
return
if 'message' in post:
if 'application' in post:
allPosts.append(Post(post['id'], post['message'].encode('utf-8'), post['created_time'],post['application']['name']))
else:
allPosts.append(Post(post['id'], post['message'].encode('utf-8'), post['created_time'], 'share by facebook application'))
else:
if 'application' in post:
allPosts.append(Post(post['id'], 'no message share', post['created_time'], post['application']['name']))
else:
allPosts.append(Post(post['id'], 'no message share', post['created_time'], 'share by facebook application'))
i += 1
# Attempt to make a request to the next page of data, if it exists.
posts = requests.get(posts["paging"]["next"]).json()
except KeyError:
return
def createNode():
length = len(fb.allPosts)
for post in range(0,length):
id = fb.allPosts[post].id
message = fb.allPosts[post].message
time = fb.allPosts[post].time
application = fb.allPosts[post].application
node = Node("Post", id=id, message=message, timestamp=time, application=application)
graph.create(node)
09-09-2019 07:58 AM
ok.. couple of concerns. my post earlier with the answer was syntactically incorrect in that
match(n:MyNode)
where date(datetime(n:timestamp))='2019-09-04' or
date(datetime(n:timestamp))< 2019-09-05'
return n
should be
match(n:MyNode)
where date(datetime(n.timestamp))='2019-09-04' or
date(datetime(n.timestamp))< '2019-09-05`
return n
such that the change is that the where clause previously referred to n:timestamp
when it should have be n.timestamp
(presuming the name of your property is named timestamp), and again enclosing 2019-09-05 in single quotes.
What match statement are you using ?
09-09-2019 08:26 AM
yes the property of the nodes is timestamp. So, I use this code
match(n:Post)
where date(datetime(n.timestamp))='2019-09-04' or
date(datetime(n.timestamp))< '2019-09-05'
return n
and I get this error
Type mismatch: expected Date but was String (line 2, column 80 (offset: 96))
Then I tried to modified the code in this way
match(n:Post)
where date(datetime(n.timestamp))='2019-09-04' or
date(datetime(n.timestamp))< '2019-09-05`
return n
Like you have written, but i get another error:
SyntaxError: Unexpected end of input: expected '', ANY
or ''' (line 3, column 9 (offset: 115)) "return n"
Finally, I proved in this way
match(n:Post)
where date(datetime(n.timestamp))='2019-09-04' or
date(datetime(n.timestamp))< `2019-09-05`
return n
and I get
.SyntaxError: Variable
2019-09-05
not defined
I know that the last solution is incorrect, but I'm not able to understand why the first test didn't work
09-09-2019 03:22 PM
You are still using backticks where you should use single quotes.
If you fix that it would work.
All the sessions of the conference are now available online