Course

Working with Dates and Durations

Work with Neo4j temporal types in Cypher: convert dates, truncate values for grouping, calculate durations, and build indexed date range queries.

35 minutes6 lessons across 1 module
About this lab

In this 35-minute lab, you will learn

This lab teaches you to work with dates, times, and durations in Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it. using Neo4j's built-in temporal types. In around 35 minutes you will move from creating your first date value to writing a query that finds a movie released last year without hardcoding a single date.

Most databases store dates as strings or integers and leave the interpretation to your application. The movies dataset is a typical example: the released Full definition for property (opens in a new tab)A named value stored on a node or a relationship. on Movie Full definition for node (opens in a new tab)A vertex in a graph. In a property graph it can carry labels and properties. and the born property on Person nodes are plain integers. These values work for simple lookups, but they cannot answer questions about time spans, date ranges, or relative ordering without manual arithmetic scattered across your queries. Neo4j's temporal types solve this at the database level: a date understands calendars, a duration understands spans of time, and the two combine into arithmetic the database evaluates natively.

  • Temporal types

    Understand Neo4j date, datetime, time, localtime, and localdatetime types and how to create them.

  • Date conversion and truncation

    Convert integer year properties into proper date values and truncate dates for grouping and index-friendly comparisons.

  • Durations and arithmetic

    Create durations, compute time spans between dates with duration.between(), and perform date arithmetic with + and - operators.

  • Date range searches

    Combine date conversion, truncation, and duration arithmetic to build temporal range queries that leverage indexes.

  • Who this course is for

    This lab is for developers, data engineers, and analysts who work with time-based data in Neo4j. If your graph records when something happened — orders placed, accounts created, films released — and you need to group events by period, calculate ages or career lengths, or find everything that happened within a window, the temporal types are the right tool. It is also for anyone who has inherited a dataset where dates arrived as integers or strings, a common situation in imported data. You should be comfortable with basic Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it., including MATCH, WHERE, WITH, and RETURN, from Cypher Fundamentals before you start.

  • What you'll do

    This is a hands-on lab, not a reading exercise. You work in an embedded sandbox connected to a live Neo4j database loaded with the movies dataset: a graph of Movie and Person Full definition for node (opens in a new tab)A vertex in a graph. In a property graph it can carry labels and properties. connected by ACTED_IN and DIRECTED Full definition for relationship (opens in a new tab)A named, directed connection between two nodes. Every relationship has a type, a start node and an end node..

    Lessons alternate between explanation and challenge. In the lessons you run worked examples: constructing dates from strings and maps, computing spans with duration.between(), adding and subtracting durations, and building index-friendly range comparisons. In the challenges you get a starter query with a gap in it, and the platform checks your result against the graph — you cannot pass by reading alone. By the end, you will have written queries that group movies by decade with date.truncate(), calculate how old actors were when their films were released, and find films within a release window that adjusts itself to today's date.

  • Where to go next

    Range searches only reach full speed when the Full definition for property (opens in a new tab)A named value stored on a node or a relationship. they filter are indexed. Cypher Indexes and Constraints is the natural next step in the Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it. path: it teaches you to create and manage the indexes that make temporal comparisons fast at scale, along with the Full definition for constraint (opens in a new tab)A rule the database enforces on every node or relationship with a given label or type, rejecting any write that breaks it. that keep your data consistent. Temporal types and functions also appear in the Neo4j Certified Professional exam, so the practice you get here counts toward a recognised credential.