GreenPlum中常用时间函数如下:
测试代码:
eda_gp=> select age('20160114','19911008');
age
------------------------
24 years 3 mons 6 days
(1 row)
eda_gp=> select age(timestamp '19911008');
age
------------------------
24 years 3 mons 6 days
(1 row)
eda_gp=> select current_date;
date
------------
2016-01-14
(1 row)
eda_gp=> select current_time;
timetz
--------------------
10:22:30.776267+08
(1 row)
eda_gp=> select current_timestamp;
now
------------------------------
2016-01-14 10:22:38.77006+08
(1 row)
eda_gp=> select date_part('hour',timestamp'20160114 10:07:30');
date_part
-----------
10
(1 row)
eda_gp=>
eda_gp=> select date_part('minute',timestamp'20160114 10:07:30');
date_part
-----------
7
(1 row)
eda_gp=> select date_part('second',timestamp'20160114 10:07:30');
date_part
-----------
30
(1 row)
eda_gp=> select date_trunc('hour',timestamp'20160114 10:07:30');
date_trunc
---------------------
2016-01-14 10:00:00
(1 row)
eda_gp=> select date_trunc('minute',timestamp'20160114 10:07:30');
date_trunc
---------------------
2016-01-14 10:07:00
(1 row)
eda_gp=> select date_trunc('second',timestamp'20160114 10:07:30');
date_trunc
---------------------
2016-01-14 10:07:30
(1 row)
eda_gp=> select extract(hour from timestamp '20160114 10:07:30');
date_part
-----------
10
(1 row)
eda_gp=> select now();
now
-------------------------------
2016-01-14 10:26:51.572545+08
(1 row)