获取月初月末日期
select date_trunc('month',now())
select date_trunc('month',now()+'1 months')+'-1 days'
同理获取当天:
select date_trunc('day',now());
-- 当季第一天
select date_trunc('quarter',now());
-- 当周第一天:
select date_trunc('week',now());
-- 小时 取整:
select date_trunc('hour',now());
把一个月份字段导出为开始时间和结束时间
to_char(date_trunc('month',to_timestamp(year_month,'yyyyMMdd')),'yyyy/mm/dd') as start_date,
to_char(date_trunc('month',to_timestamp(year_month,'yyyyMMdd')+'1 months')+'-1 days','yyyy/mm/dd') as end_date