How to round to nearest X minutes with PL/pgSQL?

后端 未结 7 1479
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 03:36

How I can round to nearest X minutes?

Here\'s my attempt:

DECLARE
  _stamp ALIAS FOR $1; -- timestamp
  _nearest ALIAS FOR $2; -- minutes (integer)
         


        
7条回答
  •  臣服心动
    2021-01-07 03:52

    This could be also useful: A function to round a Timestamp up to 5 minutes. You can easily modify it to get it working with any field of the timestamp and any quantity of that field.

    round_time function

提交回复
热议问题