how to calculate the time between two timestamps (PostgreSQL)

随声附和 提交于 2019-12-22 12:29:15

问题


Calculate the time between these two timestamps in PostgreSQL,
create_time='2017-11-02 05:51:13' and update_time='2017-11-02 07:36:18'
and display it on HH:MM:SS Format. it should display like this 01:45:04


回答1:


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');

Output:

to_char
01:45:08

Demo



来源:https://stackoverflow.com/questions/47074284/how-to-calculate-the-time-between-two-timestamps-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!