如何计算两个时间戳之间的时间(PostgreSQL) [英] how to calculate the time between two timestamps (PostgreSQL)

查看:235
本文介绍了如何计算两个时间戳之间的时间(PostgreSQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算 PostgreSQL 中这两个时间戳之间的时间,
create_time='2017-11-02 05:51:13' 和 update_time='2017-11-02 07:36:18'
并以HH:MM:SS格式显示.它应该像这样显示 01:45:04

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

推荐答案

您可以尝试将两个时间戳相减,然后使用 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

演示

这篇关于如何计算两个时间戳之间的时间(PostgreSQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆