to_char(sysdate,'yyyyiw') 会得到200937周 如果给你一个200928周 求出该周的第一天和最后一天是哪天?select to_date(substr('200928',0,4)||'0101','YYYYMMDD')+to_number(substr('200928',5,2))*7-1 as weekfirstdate from dual;
这算法 得到本年度第一天的周次,然后跟200928周次乘以天数 得到该周的第一天。
这算法 有问题 1月1号是去年的第54周,也就是说1月1号第一周不满7天。
这算法 得到本年度第一天的周次,然后跟200928周次乘以天数 得到该周的第一天。
这算法 有问题 1月1号是去年的第54周,也就是说1月1号第一周不满7天。
LZ希望从几号到几号呢?
,(sysdate - ((to_number(to_char(sysdate,'yyyyiw'))-to_number('200928'))*7)-to_number(to_char(sysdate,'d'))+7)
from dual ;
周日为第一天,周六为最后一天;
to_char(sysdate,'day')得到的星期为国外版本和国内版本
to_number(substr('200937',5,2))*7-8,1) as weekfirstdate from dual;
select next_day(to_date(substr('200937',0,4)||'0101','YYYYMMDD')+
to_number(substr('200937',5,2))*7-1,7) as weekfirstdate from dual;
这跟第一周有几天没有关系
前面减去的数需要修改下。第37周的周一,需要减去2个星期的下星期一
应该是
select next_day(to_date(substr('200937',0,4)||'0101','YYYYMMDD')+
to_number(substr('200937',5,2))*7-14,1) as weekfirstdate from dual;
select next_day(to_date(substr('200937',0,4)||'0101','YYYYMMDD')+
to_number(substr('200937',5,2))*7-8,7) as weekfirstdate from dual;