diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index 033767527..5bc92b6e8 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -75,6 +75,7 @@ *** xref:expressions/predicates/type-predicate-expressions.adoc[] ** xref:expressions/mathematical-operators.adoc[] ** xref:expressions/string-operators.adoc[] +** xref:expressions/temporal-operators.adoc[] ** xref:expressions/conditional-expressions.adoc[] * xref:functions/index.adoc[] diff --git a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc index b7df09fdb..9210f2858 100644 --- a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc +++ b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc @@ -5732,7 +5732,7 @@ Replaced by xref:values-and-types/lists.adoc#cypher-list-comprehension[list comp | xref:functions/scalar.adoc#functions-randomuuid[randomUUID()] | Function | Added | | xref:values-and-types/temporal.adoc[Temporal types] | Functionality | Added | Supports storing, indexing and working with the following temporal types: Date, Time, LocalTime, DateTime, LocalDateTime and Duration. | xref:functions/temporal/index.adoc[Temporal functions] | Functionality | Added | Functions allowing for the creation and manipulation of values for each temporal type -- _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ and _Duration_. -| xref:syntax/operators.adoc#query-operators-temporal[Temporal operators] | Functionality | Added | Operators allowing for the manipulation of values for each temporal type -- _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ and _Duration_. +| xref:expressions/temporal-operators.adoc[Temporal operators] | Functionality | Added | Operators allowing for the manipulation of values for each temporal type -- _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ and _Duration_. | xref:functions/string.adoc#functions-tostring[toString()] | Function | Extended | Now also allows temporal values as input (i.e. values of type _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ or _Duration_). |=== diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index 97415b831..3dbcd364e 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -13,5 +13,6 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. * xref:expressions/string-operators.adoc[]: `+`, `||` +* xref:expressions/temporal-operators.adoc[]: `+`, `-`, `*`, `/` * xref:expressions/conditional-expressions.adoc[] diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc new file mode 100644 index 000000000..dd1b09e29 --- /dev/null +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -0,0 +1,181 @@ += Temporal operators +:description: Information about Cypher's temporal operators. +:table-caption!: + +Cypher contains the following temporal operators: + +* Adding a xref::values-and-types/temporal.adoc#cypher-temporal-durations[`DURATION`] to either a xref::values-and-types/temporal.adoc#cypher-temporal-instants[temporal instant value] or another `DURATION`: `+` +* Subtracting a `DURATION` from either a temporal instant value or another `DURATION`: `-` +* Multiplying a `DURATION` with a xref::values-and-types/property-structural-constructed.adoc#property-types[number (`INTEGER` or `FLOAT`)]: `*` +* Dividing a `DURATION` by a number: `/` + +For additional expressions that evaluate to a xref:values-and-types/temporal.adoc[temporal value type], see: + +* xref:functions/temporal/index.adoc[Temporal functions -- instant types] +* xref:functions/temporal/duration.adoc[Temporal functions -- duration types] + +.Value returned from temporal operators +[options="header"] +|=== +| Operator | Left-hand operand | Right-hand operand | Result value type + +| `+` +| Temporal instant +| `DURATION` +| The type of the temporal instant + +| `+` +| `DURATION` +| Temporal instant +| The type of the temporal instant + +| `-` +| Temporal instant +| `DURATION` +| The type of the temporal instant + +| `+` +| `DURATION` +| `DURATION` +| `DURATION` + +| `-` +| `DURATION` +| `DURATION` +| `DURATION` + +| `*` +| `DURATION` +| Number +| `DURATION` + +| `*` +| Number +| `DURATION` +| `DURATION` + +| `/` +| `DURATION` +| Number +| `DURATION` + +|=== + +[[adding-subtracting-durations]] +== Adding and subtracting `DURATION` values + +`DURATION` values can be added and subtracted from temporal instant values, such as `LOCAL DATETIME`. +In the below example, the xref:functions/temporal/index.adoc#functions-localdatetime[`localdatetime()`] function is used to create a `LOCAL DATETIME` value, and the xref:functions/temporal/duration.adoc#functions-durations[`duration()`] function is used to create a `DURATION` value. + +.Add and subtract a `DURATION` value to/from a `LOCAL DATETIME` +[source, cypher] +---- +WITH localdatetime({year:1984, month:10, day:11, hour:12, minute:31, second:14}) AS aDateTime, + duration({years: 12, nanoseconds: 2}) AS aDuration +RETURN aDateTime + aDuration AS addition, + aDateTime - aDuration AS subtraction +---- + +.Result +[role="queryresult",options="header,footer",cols="2*