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:
Marios Trivyzas 2019-11-19 13:40:34 +01:00
parent 19602fd573
commit fd1bb4a33a
5 changed files with 93 additions and 7 deletions

View file

@ -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]