Chronological comparison operators

Chronological comparison operators compare temporal values either by instant or by representation. Cypher® contains the following chronological comparison operators:

  • Ordering:

    • IS [NOT] BEFORE

    • IS [NOT] AFTER

  • Equality:

    • IS [NOT] SAME INSTANT

    • IS [NOT] SAME REPRESENTATION

Template for chronological comparison operators
expr IS [NOT] BEFORE expr
expr IS [NOT] AFTER expr
expr IS [NOT] SAME INSTANT expr
expr IS [NOT] SAME REPRESENTATION expr

Operator behavior

Operator Result

IS [NOT] BEFORE

true if the instant of the left operand is earlier than the instant of the right operand.

IS [NOT] AFTER

true if the instant of the left operand is later than the instant of the right operand.

IS [NOT] SAME INSTANT

true if both operands denote the same instant.

IS [NOT] SAME REPRESENTATION

true if both operands have the same representation.

NOT negates the comparison using ternary logic. true becomes false, false becomes true, and null remains null.

Instant and representation

The instant of a temporal value is the point in time it denotes, regardless of the zone or offset used to write it. The representation of a temporal value is its component values, including its time zone or offset where the type has one.

For a DATETIME value, the representation is the local date-time together with the time zone or offset. For a TIME value, the representation is the local time together with the offset.

Non-zoned values, such as DATE and LOCAL DATETIME, have no time zone or offset, so their instant and their representation coincide. For these values, instant comparison and representation comparison reduce to value comparison.

The operators IS BEFORE, IS AFTER, and IS SAME INSTANT compare instants. The operator IS SAME REPRESENTATION compares representations, in the same way as =. Consequently, two zoned values can denote the same instant and still have different representations.

Compare zoned values by instant and by representation
RETURN datetime('2020-01-01T12:00Z') IS SAME INSTANT datetime('2020-01-01T13:00+01:00') AS sameInstant,
       datetime('2020-01-01T12:00Z') IS SAME REPRESENTATION datetime('2020-01-01T13:00+01:00') AS sameRepresentation
Result
sameInstant sameRepresentation

true

false

Rows: 1

Operand rules

Operands are compared only if both are of the same temporal type. The supported temporal types are: DATE, LOCAL TIME, TIME, LOCAL DATETIME, and DATETIME.

  • If either operand is null, every chronological comparison operator returns null.

  • Non-temporal values and DURATION values are not comparable.

  • Temporal operands of different type groups do not compare, for example DATE with DATETIME, or LOCAL TIME with TIME.

For operands that do not compare, the positive ordering operators IS BEFORE and IS AFTER return null, while the equality operators IS SAME INSTANT and IS SAME REPRESENTATION return false.

Compare incompatible operands
RETURN date('2020-01-01') IS BEFORE datetime('2020-01-01T00:00Z') AS beforeMixedGroups,
       date('2020-01-01') IS SAME INSTANT datetime('2020-01-01T00:00Z') AS sameInstantMixedGroups,
       1 IS NOT BEFORE 2 AS notBeforeNumbers,
       1 IS NOT SAME INSTANT 2 AS notSameInstantNumbers
Result
beforeMixedGroups sameInstantMixedGroups notBeforeNumbers notSameInstantNumbers

null

false

null

true

Rows: 1

Example graph

The following graph is used for the examples below:

Chronological comparison operators example graph

To recreate the graph and a range index on the relevant temporal property, run the following queries in an empty Neo4j database:

CREATE (:Event {name: 'Planning', startsAt: datetime('2026-10-05T12:00:00+02:00')}),
       (:Event {name: 'Review', startsAt: datetime('2026-10-05T11:00:00Z')}),
       (:Event {name: 'Retrospective', startsAt: datetime('2026-10-06T09:00:00Z')})
CREATE INDEX event_startsAt FOR (e:Event) ON (e.startsAt)

Examples

IS BEFORE in a WHERE subclause
MATCH (e:Event)
WHERE e.startsAt IS BEFORE datetime('2026-10-05T11:00:00Z')
RETURN e.name AS name, e.startsAt AS startsAt
ORDER BY name
Result
name startsAt

"Planning"

2026-10-05T12:00+02:00

Rows: 1

CASE expression
MATCH (e:Event)
RETURN e.name AS name,
       CASE e.startsAt
         WHEN IS BEFORE datetime('2026-10-05T11:00:00Z') THEN 'before'
         WHEN IS SAME INSTANT datetime('2026-10-05T11:00:00Z') THEN 'same instant'
         ELSE 'after'
       END AS position
ORDER BY name
Result
name position

"Planning"

"before"

"Retrospective"

"after"

"Review"

"same instant"

Rows: 3

Query an indexed property
MATCH (e:Event)
WHERE e.startsAt IS AFTER datetime('2026-10-05T11:00:00Z')
RETURN e.name AS name, e.startsAt AS startsAt
ORDER BY name
Result
name startsAt

"Retrospective"

2026-10-06T09:00Z

Rows: 1

A range index on the compared property can be used to answer chronological comparison operators more efficiently. IS SAME REPRESENTATION uses an exact key lookup, in the same way as =. For more information, see The impact of indexes on query performance.

Non-zoned temporal values
RETURN date('2026-10-05') IS BEFORE date('2026-10-06') AS dateBefore,
       localtime('09:00') IS AFTER localtime('10:00') AS timeAfter,
       localdatetime('2026-10-05T12:00:00') IS SAME INSTANT localdatetime('2026-10-05T12:00:00') AS sameInstant
Result
dateBefore timeAfter sameInstant

true

false

true

Rows: 1

Syntax

Syntax snippet extracted from the full Cypher grammar.
<advanced comparison predicate part 2> ::= <advanced comp op> <advanced comparison predicand> | <value type predicate part 2> | <null predicate part 2> | xref:expressions/predicates/string-operators.adoc[<normalized predicate part 2>] | <is labeled predicate part 2> 
<advanced comp op> ::= <contains operator> | <in operator> | <regex equals operator> | <start with operator> | <end with operator> | <chronological operator> 
<advanced comparison predicand> ::= <arithmetic value expression> 
<chronological operator> ::= "IS" [ "NOT" ] <chronological predicate kind> 
<chronological predicate kind> ::= "AFTER" | "BEFORE" | "SAME" { "INSTANT" | "REPRESENTATION" }
Railroad diagram of the snippet
Railroad diagram for 'expressions/chronological-operators'