我使用mysql中的week()函数来确定日期中的周数。我面临的问题是,它总是从实际的周数中返回一个较少的数字。假设今天是2013-05-15,因为它是今年的第20周,但结果是19。以下是我使用的查询。
 SELECT *,WEEK(date_visit) AS week_no FROM property_view_details;发布于 2013-05-15 23:04:14
发布于 2013-05-15 23:02:37
将第二个week参数设置为右值。
引用文档:https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
M   F.day   Range   Week 1 is the first week …
0   Sunday  0-53    with a Sunday in this year
1   Monday  0-53    with more than 3 days this year
2   Sunday  1-53    with a Sunday in this year
3   Monday  1-53    with more than 3 days this year
4   Sunday  0-53    with more than 3 days this year
5   Monday  0-53    with a Monday in this year
6   Sunday  1-53    with more than 3 days this year
7   Monday  1-53    with a Monday in this year
M = Mode
F.day = First day of week示例:
mysql> SELECT WEEK('2008-02-20',0);
        -> 7
mysql> SELECT WEEK('2008-02-20',1);
        -> 8发布于 2013-05-15 23:04:41
manual应该会对此做出一些解释。
default_week_format可能设置为默认值0,这意味着星期从零开始计数。尝试将其更改为1,或者仅调整查询以适应更改。
https://stackoverflow.com/questions/16568491
复制相似问题