Neo4j GraphDB Date Range query

Today in this article, we will see how to query the Neo4j Graph – Date Time query with examples.

We will see how to get records based on date/time greater than or less than scenarios.

We will also how to get records between 2 dates range given.

Today in this article, we will cover below aspects,

Getting started

Here below is a sample schema or document we shall use for the date range query,

Neo4j Date Cypher query – Commands with examples

Here we will be using the below query to get the documents between two dates in Neo4j Collection.

Date greater than cypher query

Command

MATCH (n:Node) WHERE n.FieldName > datetime('Date here')
return n

Where

  • FieldName – It is a date-time stamp property as expected date format

  • Node – the name of the Node.

Date Less than cypher query

Command

MATCH (n:Node) WHERE n.FieldName < datetime('Date here')
return n

Date greater than and less than the query

Command

MATCH (n:Node) WHERE n.FieldName> datetime('date here') AND  n.FieldName< datetime('date here')
return n

Let’s now look few real examples and query execution patterns.

Example – Neo4j Graph – Date Time query – Date Less than

Below is the Neo4j date query for less than dates.

Example

MATCH (n:Person) WHERE n.DateAdded < datetime('2020-06-23')
return n

The above query gives us a total of 264 nodes with relationship details.

Example – Neo4j Date query – greater than dates

Below is the Neo4j query for less than dates.

Query Pattern

MATCH (n:Person) WHERE n.DateAdded > datetime('2020-06-23')
return n

The above query gives us a total of 2 nodes with relationship details.

Neo4j cypher query – Get records between greater than and less than dates

Query Pattern :

MATCH (n:Person) WHERE n.DateAdded > datetime('2009-05-23') AND  n.DateAdded < datetime('2021-06-23')
return n

Example :

Neo4j GraphDB Date Time query with examples

The query will identify all the records falling between two specified dates.

References :

Do you have any comments or ideas or any better suggestions to share?

Please sound off your comments below.

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *