Managing Dates and Times in Neo4j with the datetime Function

17.11.2025

For web developers working with Neo4j, managing dates and times is an essential part of many applications. The datetime function in Neo4j provides a powerful tool for working with date and time values in Cypher queries. In this article, we will explore how to use the datetime function to effectively manage dates and times in Neo4j.

BloodHound – Sniffing Out the Path Through Windows Domains | SANS ...

Benefits of Using the datetime Function

  • Efficiently work with date and time values in Cypher queries.
  • Perform operations such as date arithmetic and date formatting.
  • Compare and manipulate dates and times with ease.
  • Ensure data consistency and accuracy when dealing with temporal data.

Basic Usage of the datetime Function

The datetime function in Neo4j allows you to create date and time values from strings or components such as year, month, day, hour, minute, second, and timezone offset. Here’s a basic example of using the datetime function:

5 Years of Waiting: The most anticipated JS feature is coming …
Jul 4, 2025 … … DateTime #IntlAPI … This content isn’t available. ⚡️ The biggest revolution in date and time handling in JavaScript has finally arrived!
 // Create a datetime value representing '2022-09-15T10:30:00' RETURN datetime('2022-09-15T10:30:00') AS myDateTime 

In the example above, we are creating a datetime value for September 15, 2022, at 10:30:00.

Performing Date Arithmetic

With the datetime function, you can perform date arithmetic operations such as adding or subtracting days, months, or years from a given date. Here’s an example:

 // Add 3 months to the current date RETURN datetime().plus({months: 3}) AS futureDate 

In this query, we are adding 3 months to the current date to calculate a future date.

Formatting Dates and Times

You can format date and time values using the datetime function to represent them in different styles or extract specific components such as the year or month. Here’s an example:

 // Format the current date as 'YYYY-MM-DD' RETURN datetime().format('YYYY-MM-DD') AS formattedDate 

This query formats the current date as ‘YYYY-MM-DD’.

Comparing Dates and Times

When working with temporal data, it is often necessary to compare dates and times to perform queries based on specific criteria. The datetime function allows you to compare date and time values easily. Here’s an example:

 // Compare two date values MATCH (p:Person) WHERE datetime(p.birthdate) < datetime('2000-01-01') RETURN p.name 

In this query, we are comparing the birthdate of a person with the date ‘2000-01-01’ to filter results based on the birthdate.

Handling Timezones

Dealing with timezones is crucial when working with dates and times in a global context. The datetime function in Neo4j allows you to specify a timezone offset when creating date and time values. Here’s an example:

 // Create a datetime value with a timezone offset RETURN datetime('2022-09-15T10:30:00+03:00') AS myDateTime 

In this query, we are creating a datetime value for September 15, 2022, at 10:30:00 with a timezone offset of +03:00.

Conclusion

The datetime function in Neo4j is a powerful tool for managing dates and times in Cypher queries. By leveraging the datetime function, web developers can efficiently work with temporal data, perform date arithmetic, format dates and times, compare values, and handle timezones effectively. Understanding how to use the datetime function is essential for building robust applications that rely on accurate date and time calculations.

Do you like the article?

Yan Hadzhyisky

fullstack PHP+JS+REACT developer