I have a perfectly running program which grabs information from my database on a weekly basis. My current problem is that now I have to change the program from selecting the current week (Sunday to Saturday) to selecting the week starting on Wednesday through Tuesday.
我有一个完美运行的程序,每周从我的数据库中获取信息。我目前的问题是,现在我必须将程序从选择当前周(星期日到星期六)改为选择从星期三到星期二开始的星期。
Here is the query I have now which runs fine for Sunday through Saturday:
这是我现在的查询,周日到周六运行良好:
SELECT time, roNum
FROM $user
WHERE YEAR(date) = YEAR(CURDATE()) AND WEEK(date) = WEEK(CURDATE());
Any help would be greatly appreciated. Thanks.
任何帮助将不胜感激。谢谢。
2 个解决方案
#1
1
One method for doing this is to adjust the date before extracting the date components. In this case, you can probably subtract two days before extracting the year and week:
执行此操作的一种方法是在提取日期组件之前调整日期。在这种情况下,您可以在提取年份和周之前减去两天:
SELECT time, roNum
FROM $user
WHERE YEAR(date - interval 2 day) = YEAR(CURDATE()) AND
WEEK(date - interval 2 day) = WEEK(CURDATE());
#2
0
Thank you, Gordon Linoff for getting me on the right track. Your answer helped me to figure it out. Here is the code that got me to where I needed to be:
谢谢Gordon Linoff让我走上正轨。你的回答帮助我弄明白了。这是让我到达我需要的地方的代码:
SELECT time, roNum
FROM $user
WHERE YEAR(date + interval 4 day) = YEAR(CURDATE()) AND
WEEK(date + interval 4 day) = WEEK(CURDATE())
#1
1
One method for doing this is to adjust the date before extracting the date components. In this case, you can probably subtract two days before extracting the year and week:
执行此操作的一种方法是在提取日期组件之前调整日期。在这种情况下,您可以在提取年份和周之前减去两天:
SELECT time, roNum
FROM $user
WHERE YEAR(date - interval 2 day) = YEAR(CURDATE()) AND
WEEK(date - interval 2 day) = WEEK(CURDATE());
#2
0
Thank you, Gordon Linoff for getting me on the right track. Your answer helped me to figure it out. Here is the code that got me to where I needed to be:
谢谢Gordon Linoff让我走上正轨。你的回答帮助我弄明白了。这是让我到达我需要的地方的代码:
SELECT time, roNum
FROM $user
WHERE YEAR(date + interval 4 day) = YEAR(CURDATE()) AND
WEEK(date + interval 4 day) = WEEK(CURDATE())