--获取本天 yyyy-MM-dd /2022-12-13
select current_date;
--获取本天 date /2022-12-13
select now();
--获取本天 /13
select date_part('day', current_timestamp)
--格式化 年月日-时 /2022-12-13 16
SELECT to_char(now(),'yyyy-MM-dd hh24');
--格式化 年月日-时分 /2022-12-13 16:17
SELECT to_char(now(),'yyyy-MM-dd hh24:MI');
--格式化 年月日-时分秒 /2022-12-13 16:17:53
SELECT to_char(now(),'yyyy-MM-dd hh24:MI:ss');
--格式化 年月日 /20221213
select to_char(current_date,'yyyymmdd');
--格式化 年月日 2022年12月13日
select to_char(current_date,'yyyy年mm月dd日');
--获取本月第一天 /2022-12-01 00:00:00.000 +0800
select date_trunc('month',now());
--获取本月最后一天 /2022-12-31 00:00:00.000 +0800
select date_trunc('month',now()) +interval '1 month' -interval '1 day';
--获取本月月份 /12
select date_part('month', current_timestamp)
--获取本年第一天 /2022-01-01 00:00:00.000 +0800
select date_trunc( 'year', now() );
--获取本年最后一天 /2022-12-31 00:00:00.000 +0800
select date_trunc( 'year', now() )+interval '1 year' -interval '1 day';
--获取本年年份 /2022
select date_part('year', current_timestamp);
--获取 上一天的日期 / 2022-12-12 16:30:32.481 +0800
select now() - interval '1 day';
--格式化日期 /2022-12-12 16:31:22 以下同理
SELECT to_char(now() - interval '1 day','yyyy-MM-dd hh24:MI:ss');
--获取 上一周的日期 /2022-12-06 16:31:42.240 +0800
select now() - interval '1 week';
--获取 上一个月的日期 /2022-11-13 16:31:56.145 +0800
select now() - interval '1 month';
--获取 一年前的日期 2021-12-13 16:31:56.145 +0800
select now() - interval '1 year';