# Match all node between two dates

**URL:** <https://community.neo4j.com/t/match-all-node-between-two-dates/9978>\
**Category:** Cypher\
**Tags:** cypher, operations\
**Created:** [September 9, 2019, 10:50am UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978 "2019-09-09T10:50:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lx2pwnd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lx2pwnd/32/4666_2.png) [@lx2pwnd](https://community.neo4j.com/u/lx2pwnd)\
**Post date:** [September 9, 2019, 10:50am UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/1 "2019-09-09T10:50:14Z")

</div>

I want to match all the nodes between two date. At the moment every node in my db has this form

```auto
  "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

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2019, 11:46am UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/2 "2019-09-09T11:46:55Z")

</div>

yes except I think its not liking the format of the timestamp.  
running

```auto
return datetime();

```

for example returns

```auto
2019-09-09T11:43:10.553000000Z"

```

further [Temporal (Date/Time) values - Cypher Manual](https://neo4j.com/docs/cypher-manual/3.5/syntax/temporal/#cypher-temporal-specify-date) indicates

```auto
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

```auto
match(n:MyNode) 
where date(datetime(n:timestamp_prop))='2019-09-04' or 
date(datetime(n:timestamp_prop))< 12019-09-05`;

```

---

<div class="post-metadata">

**Author:** ![lx2pwnd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lx2pwnd/32/4666_2.png) [@lx2pwnd](https://community.neo4j.com/u/lx2pwnd)\
**Post date:** [September 9, 2019, 1:37pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/3 "2019-09-09T13:37:22Z")

</div>

> [@dana\_canzano](#):
>
> match(n:MyNode) where date(datetime(n:timestamp\_prop))='2019-09-04' or date(datetime(n:timestamp\_prop))\< 12019-09-05`;

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

```auto
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"

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2019, 1:52pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/4 "2019-09-09T13:52:26Z")

</div>

maybe this is an error in formatting but line 3 appears to be

```auto
date(datetime(n:timestamp))< 2019-09-05`

```

when it should be

```auto
date(datetime(n:timestamp))< '2019-09-05'

```

---

<div class="post-metadata">

**Author:** ![lx2pwnd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lx2pwnd/32/4666_2.png) [@lx2pwnd](https://community.neo4j.com/u/lx2pwnd)\
**Post date:** [September 9, 2019, 1:56pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/5 "2019-09-09T13:56:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2019, 2:30pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/6 "2019-09-09T14:30:52Z")

</div>

how did you created the node. Can you return the contents of the node?

---

<div class="post-metadata">

**Author:** ![lx2pwnd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lx2pwnd/32/4666_2.png) [@lx2pwnd](https://community.neo4j.com/u/lx2pwnd)\
**Post date:** [September 9, 2019, 2:35pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/7 "2019-09-09T14:35:28Z")

</div>

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

```auto
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) 

```

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2019, 2:58pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/8 "2019-09-09T14:58:03Z")

</div>

ok.. couple of concerns. my post earlier with the answer was syntactically incorrect in that

```auto
match(n:MyNode) 
where date(datetime(n:timestamp))='2019-09-04' or 
date(datetime(n:timestamp))< 2019-09-05'
return n

```

should be

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![lx2pwnd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lx2pwnd/32/4666_2.png) [@lx2pwnd](https://community.neo4j.com/u/lx2pwnd)\
**Post date:** [September 9, 2019, 3:26pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/9 "2019-09-09T15:26:45Z")

</div>

yes the property of the nodes is **timestamp**. So, I use this code

```auto
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

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [September 9, 2019, 10:22pm UTC](https://community.neo4j.com/t/match-all-node-between-two-dates/9978/10 "2019-09-09T22:22:20Z")

</div>

You are still using backticks where you should use single quotes.  
If you fix that it would work.
