我使用mysql的week()函数来确定从日期开始的周数.问题是我面临的是它总是从实际周数返回少一个数字.假设今天是2013-05-15,因为它是今年的第20周,但结果却是19.以下是我正在使用的查询.
SELECT *,WEEK(date_visit) AS week_no FROM property_view_details;
Run Code Online (Sandbox Code Playgroud)
gil*_*den 12
直接来自文档:
mysql> SELECT WEEK('2008-02-20',1);
-> 8
Run Code Online (Sandbox Code Playgroud)
你可以改变的行为,WEEK由第二个参数设置为两种0或10索引或分别为1索引的结果.
将第二个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
Run Code Online (Sandbox Code Playgroud)
样品:
mysql> SELECT WEEK('2008-02-20',0);
-> 7
mysql> SELECT WEEK('2008-02-20',1);
-> 8
Run Code Online (Sandbox Code Playgroud)