使用此查询:
date(timestamp_column) >= SUBDATE(curdate(), WEEKDAY(curdate())) -
interval 1 week AND date(timestamp_column) < SUBDATE(curdate(), WEEKDAY(curdate()))
我从前一周获得了7天。我正在寻找的是Mysql(Mo-fr)中前一周的5个工作日。如果有人能提供帮助,我会非常感激。感谢
编辑谢谢:
date(timestamp_column) > DATE_FORMAT(DATE_SUB(DATE_SUB(current_date, INTERVAL DAYOFWEEK(CURRENT_DATE)+5 day), INTERVAL 1 day), '%Y%m%d')
and
date(timestamp_column) < DATE_FORMAT(DATE_SUB(current_date, INTERVAL DAYOFWEEK(CURRENT_DATE)-1 day), '%Y%m%d')does the trick, if anyone wants the code.
答案 0 :(得分:2)
添加AND DAYOFWEEK(timestamp_column) BETWEEN 2 AND 6
会有所帮助。
DAYOFWEEK(日期)
返回日期的工作日索引(1 =星期日,2 =星期一,...,7 = 星期六)。这些索引值对应于ODBC标准。
来源:https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_dayofweek