mysql查询本周的周一(星期一)和周日(星期日)
美国习惯的周一周日:
周一 : select subdate(curdate(),date_format(curdate(),’%w’)-1)
周日 : select subdate(curdate(),date_format(curdate(),’%w’)-7)
需要注意的是,mysql为美国人习惯,周日为一周的开始,为第一天, 而我们习惯,是每周一为一周的开始。
符合中国习惯的一周:
通过判断 date_format(ds,’%w’) 判断日期周的第几天,当为0时,为周日。
周一 : select subdate(ds ,if(date_format(ds,’%w’) =0, 7 ,date_format(ds,’%w’))-1)
周日 : subdate(deal.ds ,if(date_format(deal.ds,’%w’) =0, 7 ,date_format(deal.ds,’%w’))-7)
在