- age(timestamp, timestamp)
描述:将两个参数相减,并以年、月、日作为返回值。若相减值为负,则函数返回亦为负。两个参数类型必须相同,可以都带timezone,或都不带timezone。
返回值类型:interval
示例:
gbase=# SELECT age(timestamp '2001-04-10', timestamp '1957-06-13');
age
-------------------------
43 years 9 mons 27 days
(1 row)
- age(timestamp)
描述:当前时间和参数相减,入参可以带或者不带timezone。
返回值类型:interval
示例:
gbase=# SELECT age(timestamp '1957-06-13');
age
-------------------------
64 years 11 mons 4 days
(1 row)
- clock_timestamp()
描述:实时时钟的当前时间戳。
返回值类型:timestamp with time zone
示例:
gbase=# SELECT clock_timestamp();
clock_timestamp
-------------------------------
2022-05-17 16:34:14.629575+08
(1 row)
- current_date
描述:当前时间。
返回值类型:date
示例:
gbase=# SELECT current_date;
date
------------
2022-05-17
(1 row)
- current_time
描述:当前时间。
返回值类型:time with time zone
示例:
gbase=# SELECT current_time;
timetz
--------------------
16:35:00.099149+08
(1 row)
- current_timestamp
描述:当前日期及时间。
返回值类型:timestamp with time zone
示例:
gbase=# SELECT current_timestamp;
pg_systimestamp
-------------------------------
2022-05-17 16:35:08.018834+08
(1 row)
- date_part(text, timestamp)
描述:获取日期/时间值中子域的值,例如年或者小时的值。等效于extract(field from timestamp)。
timestamp类型:abstime、date、interval、reltime、time with time zone、time without time zone、timestamp with time zone、timestamp without time zone。
返回值类型:date
示例:
gbase=# SELECT date_part('hour', timestamp '2001-02-16 20:38:40');
date_part
-----------
20
(1 row)
- date_part(text, interval)
描述:获取日期/时间值中子域的值。获取月份值时,如果月份值大于12,则取与
12的模。等效于extract(field from timestamp)。
返回值类型:double precision
示例:
gbase=# SELECT date_part('month', interval '2 years 3 months');
date_part
-----------
3
(1 row)
- date_trunc(text, timestamp)
描述:截取到参数text指定的精度。
返回值类型:interval、timestamp with time zone、timestamp without time zone
示例:
gbase=# SELECT date_trunc('hour', timestamp '2001-02-16 20:38:40');
date_trunc
---------------------
2001-02-16 20:00:00
(1 row)
- trunc(timestamp)
描述:默认按天截取。示例:
gbase=# SELECT trunc(timestamp '2001-02-16 20:38:40');
trunc
---------------------
2001-02-16 00:00:00
(1 row)
- trunc(arg1, arg2)
描述:截取到arg2指定的精度。
arg1类