Using StarRocks 3.4 and having issues with negativ...
# questions-and-troubleshooting
g
Using StarRocks 3.4 and having issues with negative times being returned even though we do NOT cross a date boundary. The docs: https://docs.starrocks.io/docs/3.4/sql-reference/sql-functions/date-time-functions/timediff/ State that the function timediff "Returns the difference between two DATETIME expressions." This would be the ABS() whether A>B or A<B. It seems to work fine for when less than 12:00 in either case, but when we use a datetime > 12:00 it gives a negative value when A<B?? If it is NOT an ABS() and the return value is "expr1-expr2" then it fails in the AM but works in the PM. In either case the results are not consistent.
-- AM time test
SELECT
*timediff*(*"2025-07-01 04:28:56"*,*"2025-07-01 03:29:36"*); -- = 00:59:20
SELECT
*timediff*(*"2025-07-01 03:29:36"*,*"2025-07-01 04:28:56"*); -- = 00:59:20 -- Dates swapped and the same results returned so ABS() of the times
-- PM time test
SELECT
*TIMEDIFF*(*"2019-07-11 12:59:30"*,*"2019-07-11 16:59:21"*); -- = -3:59:51	-- Returns a NEGATIVE VALUE when time over 12:00?
SELECT
*TIMEDIFF*(*"2019-07-11 16:59:21"*,*"2019-07-11 12:59:30"*); -- = 3:59:51 -- swapped returns a positive value when over 12:00?
е
Copy code
SELECT timediff("2025-07-01 03:29:36","2025-07-01 04:28:56");
+--------------------------------------------------------+
| timediff('2025-07-01 03:29:36', '2025-07-01 04:28:56') |
+--------------------------------------------------------+
| -00:59:20                                              |
+--------------------------------------------------------+
this is on 3.3 and i dont see code changes here for 3.4 please recheck
g
SELECT
*timediff*(*"2025-07-01 03:29:36"*,*"2025-07-01 04:28:56"*);