postgsql 时间函数

来源:互联网 发布:用php写99乘法表 编辑:程序博客网 时间:2024/06/11 19:11

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());
0 0
原创粉丝点击