date_trunc()

截断时间值到指定单位的函数

date_trunc() 是一个用于将时间戳或 interval 截断到指定单位的系统函数。

date_trunc() 添加于 PostgreSQL 7.0

用法

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 可以是以下值之一

  • microseconds
  • milliseconds
  • second
  • minute
  • hour
  • day
  • week
  • month
  • quarter
  • year
  • decade
  • century
  • millennium

变更历史

示例

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)

分类

日期和时间, 系统函数

另请参阅

date_bin()

反馈

在此处 提交关于 "date_trunc()" 的任何评论、建议或更正