date_subtract() 是一个系统函数,用于从 timestamp with time zone(timestamptz)值中减去一个 interval 值。
date_subtract() 已在 PostgreSQL 16 中添加。
用法
date_subtract (timestamp with time zone,interval[,text] ) →timestamp with time zone
变更历史
- PostgreSQL 16
- 添加(提交 75bd846b)
 
示例
date_subtract() 的基本用法示例
postgres=# SHOW TimeZone; TimeZone ------------ Asia/Tokyo (1 row) postgres=# SELECT date_subtract('2023-03-20 01:40:00 Europe/Berlin', '1 day'); date_subtract ------------------------ 2023-03-19 09:40:00+09 (1 row)
通过此示例,从指定时间戳中减去一天,并以服务器的时区显示。服务器时区恰好比 UTC 早 9 小时,比柏林在该日所处的 CET(中欧时间)早 8 小时。
参考资料
- PostgreSQL 文档: 日期/时间函数
