Skip to content

Commit b3dabf6

Browse files
add docs for date_period and time_duration
1 parent a02e9b0 commit b3dabf6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

docs/reference/esql/time-spans.asciidoc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Time spans provide a way of describing a specific period of time that separates
99

1010
The time span contains two elements, an integer value and a temporal unit, both of them are required when specifying a time span.
1111

12-
Time spans are often used in datetime related grouping functions like <<esql-bucket, BUCKET>>, scalar functions like <<esql-date_trunc, DATE_TRUNC>> and arithmetic operators like `+` and `-`. There are two conversions functions that can convert string literals to time spans, <<esql-to_dateperiod, TO_DATEPERIOD>> and <<esql-to_timeduration, TO_TIMEDURATION>>.
12+
Time spans are often used in datetime related grouping functions like <<esql-bucket, BUCKET>>, scalar functions like <<esql-date_trunc, DATE_TRUNC>> and arithmetic operators like `+` and `-`. There are conversions functions that can convert string literals to time spans, <<esql-to_dateperiod, TO_DATEPERIOD>>, <<esql-to_timeduration, TO_TIMEDURATION>> and their corresponding cast operators `::DATE_PERIOD` and `::TIME_DURATION`.
1313

1414
[float]
1515
=== Examples of using time spans in {esql}
@@ -36,11 +36,17 @@ FROM employees
3636
| EVAL x = hire_date + 1 month - 1 day
3737
----
3838

39-
When a time span is provided as a string literal, `TO_DATEPERIOD`, `::DATE_PERIOD`, `TO_TIMEDURATION` or `::TIME_DURATION` can be used to convert it to its corresponding time span value.
40-
[source,txt]
39+
When a time span is provided as a name parameter in string format, `TO_DATEPERIOD`, `::DATE_PERIOD`, `TO_TIMEDURATION` or `::TIME_DURATION` can be used to convert it to its corresponding time span value.
40+
[source,console,id=esql-time-span-named-parameter]
4141
----
42-
FROM employees
43-
| EVAL x = hire_date + TO_DATEPERIOD("1 month") - "1 day":DATE_PERIOD
42+
POST /_query
43+
{
44+
"query": """
45+
FROM employees
46+
| EVAL x = hire_date + ?timespan::DATE_PERIOD, y = hire_date - TO_DATEPERIOD(?timespan)
47+
""",
48+
"params": [{"timespan" : "1 day"}]
49+
}
4450
----
4551

4652

0 commit comments

Comments
 (0)