Chronological comparison operatorsCypher 25 onlyIntroduced in Neo4j 2026.11
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
-
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 |
|---|---|
|
|
|
|
|
|
|
|
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.
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
| sameInstant | sameRepresentation |
|---|---|
|
|
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 returnsnull. -
Non-temporal values and
DURATIONvalues are not comparable. -
Temporal operands of different type groups do not compare, for example
DATEwithDATETIME, orLOCAL TIMEwithTIME.
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.
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
| beforeMixedGroups | sameInstantMixedGroups | notBeforeNumbers | notSameInstantNumbers |
|---|---|---|---|
|
|
|
|
Rows: 1 |
|||
Example graph
The following graph is used for the examples below:
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 subclauseMATCH (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
| name | startsAt |
|---|---|
|
|
Rows: 1 |
|
CASE expressionMATCH (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
| name | position |
|---|---|
|
|
|
|
|
|
Rows: 3 |
|
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
| name | startsAt |
|---|---|
|
|
Rows: 1 |
|
|
A range index on the compared property can be used to answer chronological comparison operators more efficiently.
|
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
| dateBefore | timeAfter | sameInstant |
|---|---|---|
|
|
|
Rows: 1 |
||
Syntax
<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" }