且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何计算两个时间戳之间的时间(PostgreSQL)

更新时间:2022-06-02 08:46:47

您可以尝试将两个时间戳相减,然后使用 to_char 提取出时间部分:

You can try just subtracting the two timestamps, then using to_char to extract out the time portion:

select
    SELECT to_char('2017-11-02 07:36:18'::timestamp -
                   '2017-11-02 05:51:10'::timestamp, 'HH:MI:SS');

输出:

to_char
01:45:08

演示