日期型数据不必更多描述,直奔主题吧
select cast(‘20190101‘ as date); -- 输出 "2019-01-01" select ‘20190101‘::date; -- 输出 "2019-01-01"
两个参数:两日期相减
SELECT AGE(timestamp ‘2017-01-26‘, timestamp ‘2018-01-30‘); -- 输出 "-1 years -4 days"
一个参数:以 current_date(午夜) 为标准
SELECT AGE(timestamp ‘2017-01-26‘); -- 现在时刻 2020-01-02 -- 输出 "2 years 11 mons 6 days"
有很多,具体见参考资料
select current_date; -- 当前日期 select current_time; -- 当前时间,带时区 select localtime;
select extract(year from ‘2019-01-01‘::date); -- 2019
year 可换成 month、day
未完待续...
参考资料:
https://www.yiibai.com/postgresql/postgresql-date-time.html
原文:https://www.cnblogs.com/yanshw/p/12132226.html