Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5729

The yearweek() and week() functions return a wrong value

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.5.33a
    • Fix Version/s: 5.5
    • Component/s: None
    • Labels:
    • Environment:
      Linux

      Description

      select yearweek('2014-02-25') - returns 201408 instead of 201409
      select week('2014-02-25') - returns 8 instead of 9

      It seems to be caused by incorrectly using week 201253 instead of week 201301. All dates I have tried after this week report one week too low.

      select yearweek('2012-12-31') - returns 201253 instead of 201301

      We report weekly statistics and now just discovered that all of 2013 and 2014 are one week off. Using Microsoft SQL we get the correct week numbers, but that's not an option right now.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              leifinge Leif Inge Sandberg added a comment -

              Note the discussion here; the behaviour of the week() and yearweek() functions is designed to be dependent on the default_week_format system variable.

              http://bugs.mysql.com/bug.php?id=71827

              Show
              leifinge Leif Inge Sandberg added a comment - Note the discussion here; the behaviour of the week() and yearweek() functions is designed to be dependent on the default_week_format system variable. http://bugs.mysql.com/bug.php?id=71827
              Hide
              cristian.nicoara82 Cristian Nicoara added a comment - - edited
              • the same behavior is in 5.5.35-MariaDB
                MariaDB [(none)]> select yearweek('2014-02-25')\G
                yearweek('2014-02-25'): 201408
                1 row in set (0.00 sec)
                
              • but we have the same behavior on mysql 5.1.49-3 as well.
                select yearweek('2014-02-25')\G
                yearweek('2014-02-25'): 201408
                1 row in set (0.00 sec)
                
                select yearweek('2014-01-02')\G
                yearweek('2014-01-02'): 201352
                1 row in set (0.00 sec)
                

              But I do not know if this is a bug or a feature ; because days 1 until 4 Jan 2014 are from the same week as 29 until 31 Dec 2013 ...

              Show
              cristian.nicoara82 Cristian Nicoara added a comment - - edited the same behavior is in 5.5.35-MariaDB MariaDB [(none)]> select yearweek('2014-02-25')\G yearweek('2014-02-25'): 201408 1 row in set (0.00 sec) but we have the same behavior on mysql 5.1.49-3 as well. select yearweek('2014-02-25')\G yearweek('2014-02-25'): 201408 1 row in set (0.00 sec) select yearweek('2014-01-02')\G yearweek('2014-01-02'): 201352 1 row in set (0.00 sec) But I do not know if this is a bug or a feature ; because days 1 until 4 Jan 2014 are from the same week as 29 until 31 Dec 2013 ...
              Hide
              cristian.nicoara82 Cristian Nicoara added a comment -

              And ...

              by using this approach we can change the behavior :

              MariaDB [(none)]> select yearweek('2014-01-01',1)\G
              yearweek('2014-01-01',1): 201401

              Show
              cristian.nicoara82 Cristian Nicoara added a comment - And ... by using this approach we can change the behavior : MariaDB [(none)] > select yearweek('2014-01-01',1)\G yearweek('2014-01-01',1): 201401
              Hide
              leifinge Leif Inge Sandberg added a comment -

              True; by using the mode parameter we get the standard ISO result, as mentioned in the MySQL bug above. I still view this as a bug, because the default_week_format system variable seems to have no effect. The mode parameter, however, is a workaround that makes this bug a minor one.

              Show
              leifinge Leif Inge Sandberg added a comment - True; by using the mode parameter we get the standard ISO result, as mentioned in the MySQL bug above. I still view this as a bug, because the default_week_format system variable seems to have no effect. The mode parameter, however, is a workaround that makes this bug a minor one.

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  leifinge Leif Inge Sandberg
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated: