显示基于周()结果的日期,星期日除外

时间:2016-05-27 06:47:38

标签: mysql date

所以我们都知道我们可以使用week() function.获取日期的周数。我的问题是如何显示特定周的日期,除了星期日日期?

说明..

enter image description here

根据上面的例子,我想要显示的是......

  • 2009-05-17
  • 2009-05-18
  • 2009-05-19
  • 2009-05-20
  • 2009-05-21
  • 2009-05-22

如何查询?

1 个答案:

答案 0 :(得分:1)

SET @GivenDate ='2016-05-27';

SET @YearNum = YEAR(@GivenDate);
SET @WeekNum=WEEK(@GivenDate);

select selected_date,weekday(selected_date) AS WeeKDate
from 
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where YEAR(selected_date)=@YearNum
AND WEEK(selected_date)=@WeekNum
AND WEEKDAY(selected_date)<> 6;