elasticsearch/docs/reference/esql/functions/examples/date_diff.asciidoc
Bogdan Pintea 6e314d6c2a
ESQL: Align year diffing to the rest of the units in DATE_DIFF: chronological (#113103) (#113258)
This will correct/switch "year" unit diffing from the current integer
subtraction to a crono subtraction. Consequently, two dates are (at
least) one year apart now if (at least) a full calendar year separates
them. The previous implementation simply subtracted the year part of the
dates.

Note: this parts with ES SQL's implementation of the same function,
which itself is aligned with MS SQL's implementation, which works
equivalent to an integer subtraction.

Fixes #112482.

(cherry picked from commit f7ff00f645)
2024-09-20 22:31:36 +10:00

24 lines
798 B
Text
Generated

// This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
*Examples*
[source.merge.styled,esql]
----
include::{esql-specs}/date.csv-spec[tag=docsDateDiff]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/date.csv-spec[tag=docsDateDiff-result]
|===
When subtracting in calendar units - like year, month a.s.o. - only the fully elapsed units are counted.
To avoid this and obtain also remainders, simply switch to the next smaller unit and do the date math accordingly.
[source.merge.styled,esql]
----
include::{esql-specs}/date.csv-spec[tag=evalDateDiffYearForDocs]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/date.csv-spec[tag=evalDateDiffYearForDocs-result]
|===