我如何修复weekofyear('20121231')返回1?

时间:2012-12-31 09:30:31

标签: mysql

weekofyear('20121231')返回1,而weekofyear('20121230')返回52

Mysql Ver 5,1,47 Cummunity Nt / Windows 7 32 Bit / ODBC 5.1.10 /
First day of Week : Sunday

它应该返回53但它返回1, week('20121231',1)week('20121230')在两个案例中都返回53

2 个答案:

答案 0 :(得分:3)

week需要很多论据,weekofyear只是其中一种形式,与week([date], 3)相同。

阅读manual以查看不同的替代方案。

SQLFiddle

答案 1 :(得分:0)

根据documentationweekofyear('20121231') 等同于week('20121231',1)

  

WEEKOFYEAR()是兼容性函数,相当于   WEEK(date,3)

测试它:

mysql> SELECT weekofyear('20121231'), week('20121231',1), week('20121231',3);
+------------------------+--------------------+--------------------+
| weekofyear('20121231') | week('20121231',1) | week('20121231',3) |
+------------------------+--------------------+--------------------+
|                      1 |                 53 |                  1 |
+------------------------+--------------------+--------------------+