标签:
select EXTRACT(ISOYEAR FROM fromDate_) as year_, --取得周所在的年份 EXTRACT(WEEK FROM fromDate_) as week_, --取得周所在的年份 to_char(fromDate_ ,‘YYYYMMDD‘) as fromDate_, --周的起始日期 to_char(toDate_ ,‘YYYYMMDD‘) as toDate_ --周的结束日期 from ( select (date (curDate) - 7* weeks_) as fromDate_, (date (curDate) - 7* weeks_ + 6 ) as toDate_ from ( select generate_series(1,100) weeks_, -- 间隔周数(序列,这里取100周) cast(date_trunc(‘week‘, current_date) as character varying) as curDate -- 当前日期所在周的第一天 ) as fg
Postgres 中如何取得周的起始和结束日期?(周是从周一开始算起)
标签:
原文地址:http://my.oschina.net/frankies/blog/412228