Mariadb - 以小时为单位计算日期差异
Mariadb - calculate date difference in hour
这是我的初始代码:
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
我需要以小时为单位的时差,实际上它以天为单位。有什么建议吗?
使用时间戳差异:
SELECT order_logs.order_logs_created, TIMESTAMPDIFF(HOUR ,order_logs.order_logs_created , NOW()) FROM order_logs
您可以为此使用 TIMESTAMPDIFF
:
SELECT
order_logs.order_logs_created,
TIMESTAMPDIFF(HOUR,
order_logs.order_logs_created,
NOW())
FROM
order_logs
这是我的初始代码:
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
我需要以小时为单位的时差,实际上它以天为单位。有什么建议吗?
使用时间戳差异:
SELECT order_logs.order_logs_created, TIMESTAMPDIFF(HOUR ,order_logs.order_logs_created , NOW()) FROM order_logs
您可以为此使用 TIMESTAMPDIFF
:
SELECT
order_logs.order_logs_created,
TIMESTAMPDIFF(HOUR,
order_logs.order_logs_created,
NOW())
FROM
order_logs