[英]Get previous weekday + MySQL
I need to get the previous weekday.我需要得到前一个工作日。 So when it's monday I need to get the result friday but I can't seem to understand the WEEKDAY() function.所以当它是星期一时,我需要在星期五得到结果,但我似乎无法理解 WEEKDAY() 函数。 Could someone help to start with this?有人可以帮助开始吗?
WEEKDAY()
returns 0 to 6 depending on which day of the week it is. WEEKDAY()
返回 0 到 6,具体取决于它是一周中的哪一天。 You could put logic in the code to ignore weekend conditions, and go back to the Friday.您可以在代码中加入逻辑以忽略周末条件,并返回到周五。
Returns the weekday index for date (0 = Monday, 1 = Tuesday, … 6 = Sunday).返回日期的工作日索引(0 = 星期一,1 = 星期二,... 6 = 星期日)。
So if WEEKDAY(date) - 1 == 5 || WEEKDAY(date) - 1 == 6
所以如果WEEKDAY(date) - 1 == 5 || WEEKDAY(date) - 1 == 6
WEEKDAY(date) - 1 == 5 || WEEKDAY(date) - 1 == 6
then make it equal 4 (Friday) instead. WEEKDAY(date) - 1 == 5 || WEEKDAY(date) - 1 == 6
然后改为等于 4(星期五)。
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_weekday http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_weekday
Try following尝试以下
select date_add(curdate(), interval
case weekday(curdate())
when 0 then 5
when 6 then -2
else -1
end
day);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.