MySQL
SELECT TIMESTAMPDIFF(HOUR, '2023-10-01 12:00:00', '2023-10-02 15:30:00') AS hours_difference;
PostgreSQL
//EXTRACT(EPOCH FROM ('2023-10-02 15:30:00'::timestamp - '2023-10-01 12:00:00'::timestamp))
// 获取的是两个时间相差的秒数,在此基础上除3600获取相差的小时数,或者进行其他计算
SELECT EXTRACT(EPOCH FROM ('2023-10-02 15:30:00'::timestamp - '2023-10-01 12:00:00'::timestamp)) / 3600 AS hours_difference;
SQL Server
SELECT DATEDIFF(HOUR, '2023-10-01 12:00:00', '2023-10-02 15:30:00') AS hours_difference;