如何使用 postgres 将间隔转换为小时数? [英] How do I convert an interval into a number of hours with postgres?

查看:18
本文介绍了如何使用 postgres 将间隔转换为小时数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个区间

4 days 10:00:00

在 postgres 中.我如何将其转换为小时数(在这种情况下为 106?)是否有功能,或者我应该硬着头皮做类似的事情

in postgres. How do I convert that to a number of hours (106 in this case?) Is there a function or should I bite the bullet and do something like

extract(days, my_interval) * 24 + extract(hours, my_interval)

推荐答案

可能最简单的方法是:

SELECT EXTRACT(epoch FROM my_interval)/3600

这篇关于如何使用 postgres 将间隔转换为小时数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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