Datetime objects

We have three different examples here:

  1. datetime()

  2. date()

  3. duration() – in form of a dictionary where keys are minutes, seconds etc and the values are the amount

Cypher also supports APOC library for parsing string dates as follows:

WITH“25 September 2019 06:29:39”, “ms”, “dd MMMM yyyy HH:mm:ss”) AS ms

MATCH (article:Article {title: “Dates, Datetimes, and Durations in Neo4j”})

SET article.created = datetime({epochmillis: ms})

Formatting values

To format datetime objects, we can use temporal functions from APOC:

MATCH (article:Article)

RETURN article.title AS title,

apoc.temporal.format(article.created, “dd MMMM yyyy HH:mm”) AS created,
apoc.temporal.format(article.datePublished,”dd MMMM yyyy”) AS datePublished,
apoc.temporal.format(article.readingTime, “mm:ss”) AS readingTime

If we want to compare durations we need to add those durations to dates!


There are two different types of subqueries:

  1. Existential subqueries in a WHERE clause

  2. Result returning subqueries using the CALL {} syntax

Existential subqueries

We can use the EXISTS {} clause (different than exists() function) that allows us to do more powerful pattern filtering. For example, the below query allows us to find a person who works for a company that also likes technology that’s liked by at least 3 other people.

MATCH (person:Person)-[:WORKS_FOR]->(company)


MATCH (person)-[:LIKES]->(t:Technology)
WHERE size((t)<-[:LIKES]-()) >= 3

RETURN as person, AS company;

Result returning subqueries

The CALL {} clause gives us:

  1. the UNION approach to run queries and remove duplicates

  2. Sort the results afterwards



Data Scientist

Leave a Reply