SELECT DATE_FORMAT("2019-01-01", "%x%v") AS currentWeek;%v一周以周一開始,得以下結果:20160101(五) -> 20155320170101(日) -> 20165220180101(一) -> 20180120181231(一) -> 20190120190101(二) -> 201901如果以一年第1個周一為起點,那16、17年是正確的這個結果特別費解,有人解疑麼?
2 回答

慕沐林林
TA貢獻2016條經驗 獲得超9個贊
If the week containing January 1 has 4 or more days in the new year, it is week 1.
Otherwise, it is the last week of the previous year, and the next week is week 1.
回到題目
20160101 最開始一周在 2016 年小于 4 天,所以屬于 2015 最后一周
20170101 最開始一周在 2017 年小于 4 天,所以屬于 2016 最后一周
20180101 最開始一周在 2018 年大于 4 天,所以屬于 2018 第一周
...
以此類推
參考: MySQL: function_week
添加回答
舉報
0/150
提交
取消