Contents
date_trunc()
A function for truncating a time value to a specified unit
date_trunc()
is a system function for truncating a timestamp or interval
to a specified unit.
date_trunc()
was added in PostgreSQL 7.0.
Usage
date_trunc(field
text
,source
timestamp
)
date_trunc(field
text
,source
timestamp with time zone
[,time_zone
text
])
date_trunc(field
text
,source
interval
)
field
can be one of the following values:
microseconds
milliseconds
second
minute
hour
day
week
month
quarter
year
decade
century
millennium
Change history
- PostgreSQL 8.0
week
added as supportedfield
value (commit 19739718)
- PostgreSQL 7.0
- added, replacing
interval_trunc()
andtimestamp_trunc()
(commit 64568100)
- added, replacing
Examples
Basic usage example for date_trunc()
:
postgres=# SELECT now(), date_trunc('minute', now()); now | date_trunc -------------------------------+------------------------ 2021-02-24 08:24:02.582402+01 | 2021-02-24 08:24:00+01 (1 row)
References
- PostgreSQL documentation: date_trunc