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

后端 未结 7 1516
伪装坚强ぢ
伪装坚强ぢ 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 04:07

    Use the function date_trunc('src', timestamp [value]).

    See the documentation: http://www.postgresql.org/docs/9.1/static/functions-datetime.html

提交回复
热议问题