代码之家  ›  专栏  ›  技术社区  ›  Michail Michailidis

mysql date_format()-在%u和%v标志之间有什么区别?

  •  1
  • Michail Michailidis  · 技术社区  · 6 年前

    我在mysql的文档中看到了 date_format() 它返回53或54个不同的值。据我所知,几年有52周或53周。这额外的一周是从哪里来的?

    %U  Week where Sunday is the first day of the week (00 to 53)
    %u  Week where Monday is the first day of the week (00 to 53)
    %V  Week where Sunday is the first day of the week (01 to 53). Used with %X
    %v  Week where Monday is the first day of the week (01 to 53). Used with %X
    

    https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

    那么U和V标志有什么区别呢?U标志的范围不应该是(00到52)吗?

    谢谢!

    1 回复  |  直到 6 年前
        1
  •  2
  •   Michał Turczyn    6 年前

    从您在玩2018-01-01(星期一)-2018-01-07(星期日)的日期时可以看到:

    • 那个 V S可以返回上一年的周数:

    SELECT DATE_FORMAT("2018-01-05", "%V");

    返回53(本周从2017年的星期日开始)。 %v 工作原理相同,但对于上面的情况,返回0,因为星期一是一周的第一天,并且已经在2018年。

    • U s不具有该属性:对于上面的 %U 将返回1。