文档 / 函数百科 / 时间/日期函数和操作符
FUNCTION时间/日期函数和操作符
date_trunc
截断到指定的精度;参见 Section 9.9.2
Truncate to specified precision; see Section 9.9.2
时间/日期函数和操作符 引入 9.0(基线) 现存至 20 devel 4 条签名 3 次签名变更
- 分组
- 时间/日期函数和操作符
- 签名数
- 4 条
- 引入版本
- 9.0(基线)
- 状态
- 现存
- 签名变更
- 3 次
- 本版来源
- 本站译文
版本轨迹
相对 PostgreSQL 17:新增 1 条签名,移除 1 条。
签名
PostgreSQL 18 里 date_trunc 的 4 条签名,按上游手册顺序排列。参数名用斜体,类型用弱化色, 之后是返回类型。说明取自本站手册译文:标「沿用」的借用了另一版的译文,标「EN」的本站暂无译文、按英文原文显示。
-
date_trunc(text,timestamp) →timestamp截断到指定的精度;参见 Section 9.9.2date_trunc('hour', timestamp '2001-02-16 20:38:40')2001-02-16 20:00:00
-
date_trunc(text,timestamp with time zone,text) →timestamp with time zone在规定的时区中截断到指定的精度;参见 Section 9.9.2date_trunc('day', timestamptz '2001-02-16 20:38:40+00', 'Australia/Sydney')2001-02-16 13:00:00+00
-
date_trunc(text,interval) →interval截断到指定的精度;参见 Section 9.9.2date_trunc('hour', interval '2 days 3 hours 40 minutes')2 days 03:00:00
-
新
date_trunc(field,source[,time_zone])ENsourceis a value expression of typetimestamp,timestamp with time zone, orinterval. (Values of typedateandtimeare cast automatically totimestamporinterval, respectively.)fieldselects to which precision to truncate the input value. The return value is likewise of typetimestamp,timestamp with time zone, orinterval, and it has all fields that are less significant than the selected one set to zero (or one, for day and month).
本版移除的签名
PostgreSQL 17 有、18 不再有的 1 条签名,取自上一版快照。
-
date_trunc(field, source [, time_zone ])source是类型timestamp或interval的值表达式(类型date和 time的值都分别被自动转换成timestamp, timestamp with time zone,或者interval)。field选择对输入值选用什么样的精度进行截断。返回的值是timestamp, timestamp with time zone,类型或者所有小于选定的 精度的域都设置为零(或者一,对于日期和月份)的interval。
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的签名。
-
PostgreSQL 18 ← 17 签名变更
date_trunc(field, source [, time_zone])date_trunc(field, source [, time_zone ]) -
PostgreSQL 13 ← 12 手册重排
这一跳手册重排了函数表的写法,签名文本整体改写,只记函数的增删,不逐条比较签名。
-
PostgreSQL 12 ← 11 签名变更
date_trunc ( text, timestamp with time zone, text ) → timestamp with time zonedate_trunc(field, source [, time_zone ])date_trunc('field', source)说明更新 -
PostgreSQL 9.4 ← 9.3 签名变更
date_trunc ( text, interval ) → interval
签名矩阵
每条签名在给出了签名的 18 个版本里的存在情况;方格指向该版的签名。只在正文里提到此函数、没有给出签名的版本不列进来,上面的版本轨迹里仍然有它们。签名文本在 PostgreSQL 13 前后写法不同,跨越那一跳的同一条签名会显示成两行。
存在 不存在
| 签名 | 9.0 | 9.1 | 9.2 | 9.3 | 9.4 | 9.5 | 9.6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_trunc ( text, timestamp ) → timestamp |
存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 |
date_trunc('field', source) |
存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 |
date_trunc ( text, interval ) → interval |
不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 |
date_trunc ( text, timestamp with time zone, text ) → timestamp with time zone |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 |
date_trunc(field, source [, time_zone ]) |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 不存在 | 不存在 | 不存在 |
date_trunc(field, source [, time_zone]) |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 | 存在 |
同组函数
| 函数 | 签名 | 主签名 | 版本变动 | 最近变更 |
|---|---|---|---|---|
age基线 |
3 | age ( timestamp, timestamp ) → interval |
— | |
| 减去参数,生成一个使用年和月,而不是只用日的“符号化”的结果 | 现存 | |||
clock_timestamp基线 |
2 | clock_timestamp ( ) → timestamp with time zone |
— | |
| 当前日期和时间(在语句执行期间变化);参见Section 9.9.5 | 现存 | |||
current_date基线 |
1 | current_date → date |
— | |
| 当前日期;参见 Section 9.9.5 | 现存 | |||
current_time基线 |
3 | current_time → time with time zone |
— | |
| 一天中的当前时间;参见 Section 9.9.5 | 现存 | |||
current_timestamp基线 |
3 | current_timestamp → timestamp with time zone |
— | |
| 当前日期和时间 (当前事务的开始);参见 Section 9.9.5 | 现存 | |||
date_add |
1 | date_add ( timestamp with time zone, interval [, text ] ) → timestamp with time zone |
— | |
| 将一个 interval 加到 timestamp with time zone 上,并根据第三个参数命名的时区,或在省略该参数时根据当前TimeZone设置,计算时刻和夏令时调整。 | 现存 | |||
date_bin |
2 | date_bin ( interval, timestamp, timestamp ) → timestamp |
— | |
| 将输入按指定的间隔进行分箱(bin),对齐到指定的原点;参见Section 9.9.3 | 现存 | |||
date_part基线 |
3 | date_part ( text, timestamp ) → double precision |
— | |
| 获取时间戳字段 (等同于 extract);参见 Section 9.9.1 | 现存 | |||
date_subtract |
1 | date_subtract ( timestamp with time zone, interval [, text ] ) → timestamp with time zone |
— | |
| 从一个 timestamp with time zone 中减去 interval,并根据第三个参数命名的时区,或在省略该参数时根据当前TimeZone设置,计算时刻和夏令时调整。 | 现存 | |||
date_trunc基线 |
4 | date_trunc ( text, timestamp ) → timestamp |
183 次 | |
| 截断到指定的精度;参见 Section 9.9.2 | 现存 | |||
extract基线 |
3 | extract ( field FROM timestamp ) → numeric |
192 次 | |
| 获取时间戳子字段;参见 Section 9.9.1 | 现存 | |||
isfinite基线 |
3 | isfinite ( date ) → boolean |
— | |
| 测试有限日期(不是+/-无限) | 现存 | |||
justify_days基线 |
1 | justify_days ( interval ) → interval |
— | |
| 调整间隔,将30天的时间段转换为月份 | 现存 | |||
justify_hours基线 |
1 | justify_hours ( interval ) → interval |
— | |
| 调整间隔,将24小时时间段转换为天数 | 现存 | |||
justify_interval基线 |
1 | justify_interval ( interval ) → interval |
— | |
| 使用 justify_days 和 justify_hours调整时间间隔; 通过额外的符号调整 | 现存 | |||
localtime基线 |
3 | localtime → time |
— | |
| 一天中当前时间;参见 Section 9.9.5 | 现存 | |||
localtimestamp基线 |
3 | localtimestamp → timestamp |
— | |
| 当前日期和时间(当前事务的开始);参见 Section 9.9.5 | 现存 | |||
make_date |
1 | make_date ( year int, month int, day int ) → date |
— | |
| 从年、月和日字段创建日期(负数年份表示BC) | 现存 | |||
make_interval |
1 | make_interval ( [ years int [, months int [, weeks int [, days int [, hours int [, mins int [, secs double precision ]]]]]]] ) → interval |
— | |
| 从年、月、周、日、小时、分钟和秒字段创建时间间隔,每个字段默认为0 | 现存 | |||
make_time |
1 | make_time ( hour int, min int, sec double precision ) → time |
— | |
| 从小时、分钟和秒字段创建时间 | 现存 | |||
make_timestamp |
1 | make_timestamp ( year int, month int, day int, hour int, min int, sec double precision ) → timestamp |
— | |
| 从年、月、日、小时、分钟和秒字段创建时间戳(负数年份表示BC) | 现存 | |||
make_timestamptz |
1 | make_timestamptz ( year int, month int, day int, hour int, min int, sec double precision [, timezone text ] ) → timestamp with time zone |
— | |
| 从年,月,日,小时,分钟和秒字段结合时区创建时间戳(负数年份表示BC)。 | 现存 | |||
now基线 |
2 | now ( ) → timestamp with time zone |
— | |
| 当前日期和时间(当前事务的开始);参见 Section 9.9.5 | 现存 | |||
pg_sleep基线 |
1 | pg_sleep ( double precision ) |
— | |
| pg_sleep使当前会话的进程休眠,直到过去给定的秒数。 | 现存 | |||
pg_sleep_for |
1 | pg_sleep_for ( interval ) |
— | |
| pg_sleep使当前会话的进程休眠,直到过去给定的秒数。 | 现存 | |||
pg_sleep_until |
1 | pg_sleep_until ( timestamp with time zone ) |
— | |
| pg_sleep使当前会话的进程休眠,直到过去给定的秒数。 | 现存 | |||
statement_timestamp基线 |
2 | statement_timestamp ( ) → timestamp with time zone |
— | |
| 当前日期和时间(当前语句的开始);参见 Section 9.9.5 | 现存 | |||
timeofday基线 |
2 | timeofday ( ) → text |
— | |
| 当前的日期和时间 (类似 clock_timestamp, 但是采用 text 字符串);参见 Section 9.9.5 | 现存 | |||
transaction_timestamp基线 |
2 | transaction_timestamp ( ) → timestamp with time zone |
— | |
| 当前日期和时间(当前事务的开始);参见 Section 9.9.5 | 现存 | |||