TIMESTAMP_ROUND
Rounds the specified TIMESTAMP. If you omit the precision argument, TIMESTAMP_ROUND
rounds to day (DD
) precision.
Behavior Type
Syntax
TIMESTAMP_ROUND ( rounding‑target[, 'precision'] )
Parameters
rounding‑target |
An expression that evaluates to one of the following data types: |
precision |
A string constant that specifies precision for the rounded value, one of the following:
Note: Hour, minute, and second rounding is not supported by |
Examples
Round to the nearest hour:
=> SELECT TIMESTAMP_ROUND(CURRENT_TIMESTAMP, 'HH'); ROUND --------------------- 2016-04-28 15:00:00 (1 row)
Round to the nearest month:
=> SELECT TIMESTAMP_ROUND('9-22-2011 12:34:00'::TIMESTAMP, 'MM'); ROUND --------------------- 2011-10-01 00:00:00 (1 row)