mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-29 18:03:32 -04:00
SQL: Fix issue with mins & hours for DATEDIFF (#49252)
Previously, DATEDIFF for minutes and hours was doing a
rounding calculation using all the time fields (secs, msecs/micros/nanos).
Instead it should first truncate the 2 dates to the respective field (mins or hours)
zeroing out all the more detailed time fields and then make the subtraction.
(cherry picked from commit 124cd18e20
)
This commit is contained in:
parent
19602fd573
commit
fd1bb4a33a
5 changed files with 93 additions and 7 deletions
|
@ -395,6 +395,20 @@ include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeSeconds]
|
|||
include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateQuarters]
|
||||
--------------------------------------------------
|
||||
|
||||
[NOTE]
|
||||
For `hour` and `minute`, `DATEDIFF` doesn't do any rounding, but instead first truncates
|
||||
the more detailed time fields on the 2 dates to zero and then calculates the subtraction.
|
||||
|
||||
[source, sql]
|
||||
--------------------------------------------------
|
||||
include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeHours]
|
||||
--------------------------------------------------
|
||||
|
||||
[source, sql]
|
||||
--------------------------------------------------
|
||||
include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeMinutes]
|
||||
--------------------------------------------------
|
||||
|
||||
[source, sql]
|
||||
--------------------------------------------------
|
||||
include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateMinutes]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue