首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mysql week()函数返回的实际周数少了一个

mysql week()函数返回的实际周数少了一个
EN

Stack Overflow用户
提问于 2013-05-15 22:58:58
回答 4查看 10K关注 0票数 0

我使用mysql中的week()函数来确定日期中的周数。我面临的问题是,它总是从实际的周数中返回一个较少的数字。假设今天是2013-05-15,因为它是今年的第20周,但结果是19。以下是我使用的查询。

代码语言:javascript
复制
 SELECT *,WEEK(date_visit) AS week_no FROM property_view_details;
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-05-15 23:04:14

直接从docs

代码语言:javascript
复制
mysql> SELECT WEEK('2008-02-20',1);
    -> 8

对于0索引或1索引的结果,您可以通过将第二个参数设置为01来更改WEEK的行为。

票数 12
EN

Stack Overflow用户

发布于 2013-05-15 23:02:37

将第二个week参数设置为右值。

引用文档:https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week

代码语言:javascript
复制
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

示例:

代码语言:javascript
复制
mysql> SELECT WEEK('2008-02-20',0);
        -> 7
mysql> SELECT WEEK('2008-02-20',1);
        -> 8
票数 7
EN

Stack Overflow用户

发布于 2013-05-15 23:04:41

manual应该会对此做出一些解释。

default_week_format可能设置为默认值0,这意味着星期从零开始计数。尝试将其更改为1,或者仅调整查询以适应更改。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16568491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档