SQL DATEDIFF returns 错误结果
SQL DATEDIFF returns wrong result
我的SQL查询如下,
SELECT CAST(-1 * DATEDIFF(hour, '21-APR-2019 11:30:00 AM', '22-APR-2019
2:15:20 PM') % 24 AS VARCHAR)
上述查询的输出:-
-3
预期输出:-
-2
这是因为:
DATEDIFF(hour, '21-APR-2019 11:30:00 AM', '22-APR-2019
2:15:20 PM')
returns 27
而不是 26
.
更改为:
SELECT CAST(-1 * (DATEDIFF(minute, '21-APR-2019 11:30:00 AM', '22-APR-2019
2:15:20 PM') / 60) % 24 AS VARCHAR)
我的SQL查询如下,
SELECT CAST(-1 * DATEDIFF(hour, '21-APR-2019 11:30:00 AM', '22-APR-2019
2:15:20 PM') % 24 AS VARCHAR)
上述查询的输出:-
-3
预期输出:-
-2
这是因为:
DATEDIFF(hour, '21-APR-2019 11:30:00 AM', '22-APR-2019
2:15:20 PM')
returns 27
而不是 26
.
更改为:
SELECT CAST(-1 * (DATEDIFF(minute, '21-APR-2019 11:30:00 AM', '22-APR-2019
2:15:20 PM') / 60) % 24 AS VARCHAR)