gpt4 book ai didi

mysql - MySQL WEEK() 的什么模式符合 ISO 8601

转载 作者:IT老高 更新时间:2023-10-28 12:58:04 26 4
gpt4 key购买 nike

MySQL的WEEK()是什么模式函数产生 ISO 8601 week of the year ? WEEK() 的参数 2 根据此图表设置模式:

+--------------------------------------------------------------------+
| Mode | First day of week | 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 |
+--------------------------------------------------------------------+

这些模式中的一种是否会提供一年中的 ISO 8601 周?

最佳答案

在 ISO 周编号中,星期一是一周的第一天,因此仅此一项就可以将其缩小为奇数模式之一。

Per Wikipedia :

There are mutually equivalent descriptions of week 01:

  • the week with the year's first Thursday in it (the formal ISO definition),
  • the week with 4 January in it,
  • the first week with the majority (four or more) of its days in the starting year, and
  • the week starting with the Monday in the period 29 December – 4 January.

这些描述中的第三个匹配上表中的“今年超过 3 天”,所以现在我们将其缩小到 1 或 3。

最后,仍然来自维基百科(强调添加):

If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00).

因此,范围必须是 1-53,而不是 0-53。这反过来意味着正确的模式是模式 3

关于mysql - MySQL WEEK() 的什么模式符合 ISO 8601,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11788885/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com