https://www.postgresql.org/docs/9.2/static/functions-datetime.html
时间获取
获取当前完整时间
select now();
或
select current_timestamp;
获取当前日期
select current_date;
获取当前时间
select current_time;
时间计算
一年后
select now() + interval '1 year';
两月前
select now() - interval '2 month';
三周前
select now() - interval '3 week';
4小时后
select current_timestamp + interval '4 hour';
5分钟前
select current_timestamp - interval '5 min';
时间差函数
age(timestamp, timestamp)
时间字段的截取
EXTRACT(field FROM source)
例如:
select extract(year from now());
select extract(month from now());
查看今天是一年中的第几天
select extract(doy from now());