gpt4 book ai didi

postgresql - Postgres : how do you round a timestamp up or down to the nearest minute?

转载 作者:行者123 更新时间:2023-11-29 11:05:10 25 4
gpt4 key购买 nike

是否有一个 postgresql 函数可以返回四舍五入到最近的分钟的时间戳?输入值是时间戳,返回值应该是时间戳。

最佳答案

使用内置函数date_trunc(text, timestamp),例如:

select date_trunc('minute', now())

编辑:截断到最近分钟。要获得四舍五入结果,请先将时间戳加上 30 秒,例如:

select date_trunc('minute', now() + interval '30 second')

这将返回最近的分钟。

参见 Postgres Date/Time Functions and Operators了解更多信息

关于postgresql - Postgres : how do you round a timestamp up or down to the nearest minute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6195439/

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