gpt4 book ai didi

postgresql - postgres中excel的hour()函数(等价)

转载 作者:行者123 更新时间:2023-11-29 12:51:56 30 4
gpt4 key购买 nike

我最近在使用 postgres,我必须做一些计算。然而我一直没能模仿Excel的HOUR()函数,我看了official information但这对我帮助不大。

函数接收一个小数,并得到小数的时、分、秒,例如小数0,99988426返回11:59:50。尝试在 postgres(我使用 PostgreSQL 10.4)中使用 to_timestamp 函数执行此操作: select to_char (to_timestamp (0.99988426), 'HH24: MI: SS');本次返程 19:00:00。我肯定遗漏了什么,关于如何解决这个问题的一些想法?

最佳答案

24:00:00 or 86400 seconds = 1 
Half day(12:00 noon) or 43200 seconds = 43200/86400 = 0.5
11:59:50 or 86390 seconds = 86390/86400 = 0.99988426

因此,要将您的十进制值转换为时间,您所要做的就是将它乘以 86400,这将为您提供秒数,并通过以下方式将其转换为您的格式:

SELECT TO_CHAR((0.99988426 * 86400) * '1 second'::interval, 'HH24:MI:SS');

SELECT (0.99988426 * 86400) * interval '1 sec';

关于postgresql - postgres中excel的hour()函数(等价),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51863398/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com