Mariadb - 以小时计算日期差异

时间:2017-01-29 06:27:06

标签: sql mariadb datediff

这是我的初始代码:

SELECT order_logs.order_logs_created, DATEDIFF(HOUR ,NOW(),order_logs.order_logs_created) FROM order_logs

我发了一个错误:

#1582 - Incorrect parameter count in the call to native function 'DATEDIFF'

然后,我搜索了MariaDB的DATEDIFF,我看到this,我发现我可以使用带有两个参数的DATEDIFF,所以我删除了HOUR:

SELECT order_logs.order_logs_created, DATEDIFF(NOW(),order_logs.order_logs_created) FROM order_logs

我需要几个小时的时间差异,实际上它给了我几天。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

您可以使用TIMESTAMPDIFF

SELECT 
    order_logs.order_logs_created,
    TIMESTAMPDIFF(HOUR,
        order_logs.order_logs_created,
        NOW())
FROM
    order_logs

答案 1 :(得分:0)

使用TIMESTAMPDIFF:

SELECT order_logs.order_logs_created, TIMESTAMPDIFF(HOUR ,order_logs.order_logs_created , NOW()) FROM order_logs