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

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)

Categories

Date and time, System function

See also

date_bin()