Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Not a Bug
-
5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL)
-
None
Description
Using extract to get number of hours from a time_diff function produces incorrect results when number of hours is greater than 23.
Here's the details...
SET @prev_ts = '2017-11-30 11:00:00'; |
SELECT NOW() |
, TIMEDIFF(NOW(),@prev_ts)
|
, TIME_FORMAT(TIMEDIFF(NOW(),@prev_ts), '%H') AS 'diff TIME_FORMAT' |
, EXTRACT(HOUR FROM TIMEDIFF(NOW(),@prev_ts)) AS 'diff EXTRACT ' |
;
|
/*
|
NOW() TIMEDIFF(NOW(),@prev_ts) diff TIME_FORMAT diff EXTRACT
|
2017-12-15 20:58:25 369:58:25 369 9
|
*/ |
SET @prev_ts = '2017-12-14 22:00:00'; |
SELECT NOW() |
, TIMEDIFF(NOW(),@prev_ts)
|
, TIME_FORMAT(TIMEDIFF(NOW(),@prev_ts), '%H') AS 'diff TIME_FORMAT' |
, EXTRACT(HOUR FROM TIMEDIFF(NOW(),@prev_ts)) AS 'diff EXTRACT ' |
;
|
/*
|
NOW() TIMEDIFF(NOW(),@prev_ts) diff TIME_FORMAT diff EXTRACT
|
2017-12-15 21:19:32 23:19:32 23 23
|
*/ |
I think this is working as designed. Extract (hour from ..) is meant to be hour of day not total hours. This behaves the same in both columnstore and regular mariadb 10.2. Is your goal to calculate the total number of hours between the 2 dates, if so i think the following is what you need:
select timestampdiff(hour, @prev_ts, now());