您的位置:首页 > 其它

greenplum 日期及时间函数及时间的加减

2017-10-17 12:17 267 查看

1.日期和时间间字段

date:日期字段,格式:2016-04-15

timestamp:时间字段,格式:2016-04-15 20:00:00

2.获取当时时间函数

select now();

select current_timestamp;

select CURRENT_TIME;

select LOCALTIME;

select LOCALTIMESTAMP;

3.获取当天日期

select current_date;



4.日期计算:


--使用interval

当前时间加2天

select now()+interval '2 day';

当前时间减2天

select now()-interval '2 day';

当前时间减1个月

select now()-interval '-2 mon';

当前时间减2小时

select now()+interval '2 hour';



5.时间截取


显示年

select extract(year from now());

显示月

select extract(mon from now());

6.时间转换

显示年月日时分秒

select timestamp '2012-05-12 18:54:54';

显示年月日

select date '2012-05-12 18:54:54';

显示年月日时分秒+毫秒

select TIMESTAMP WITH TIME ZONE '2012-05-12 18:54:54' ;

7.与unix时间戳的转换

SELECT TIMESTAMP 'epoch' + 1341174767 * INTERVAL '1 second';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: