Yearweek returns different results

Multi tool use
Multi tool use












1















Why are the YEARWEEKs of the both following dates different?
Both dates (2018-12-29 AND 2018-12-30) are in the same week?



SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
SELECT CURDATE(); = 2018-12-30
SELECT YEARWEEK(CURDATE()); = 201852









share|improve this question





























    1















    Why are the YEARWEEKs of the both following dates different?
    Both dates (2018-12-29 AND 2018-12-30) are in the same week?



    SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
    SELECT CURDATE(); = 2018-12-30
    SELECT YEARWEEK(CURDATE()); = 201852









    share|improve this question



























      1












      1








      1








      Why are the YEARWEEKs of the both following dates different?
      Both dates (2018-12-29 AND 2018-12-30) are in the same week?



      SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
      SELECT CURDATE(); = 2018-12-30
      SELECT YEARWEEK(CURDATE()); = 201852









      share|improve this question
















      Why are the YEARWEEKs of the both following dates different?
      Both dates (2018-12-29 AND 2018-12-30) are in the same week?



      SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
      SELECT CURDATE(); = 2018-12-30
      SELECT YEARWEEK(CURDATE()); = 201852






      mysql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '18 at 3:51









      Rick James

      67.3k55899




      67.3k55899










      asked Dec 30 '18 at 0:24









      itrangeritranger

      123




      123
























          2 Answers
          2






          active

          oldest

          votes


















          2














          The default mode of operation of YEARWEEK and WEEK is set by the default_week_format system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example



          SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1) 


          Output:



          201852    201852





          share|improve this answer































            0














            Consider



            SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
            SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday


            while 2018-01-06 seems to return 201801.



            returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays






            share|improve this answer
























            • Thank you very much! How can I get the same "week-value" for both dates?

              – itranger
              Dec 30 '18 at 0:46











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974375%2fyearweek-returns-different-results%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            The default mode of operation of YEARWEEK and WEEK is set by the default_week_format system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example



            SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1) 


            Output:



            201852    201852





            share|improve this answer




























              2














              The default mode of operation of YEARWEEK and WEEK is set by the default_week_format system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example



              SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1) 


              Output:



              201852    201852





              share|improve this answer


























                2












                2








                2







                The default mode of operation of YEARWEEK and WEEK is set by the default_week_format system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example



                SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1) 


                Output:



                201852    201852





                share|improve this answer













                The default mode of operation of YEARWEEK and WEEK is set by the default_week_format system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example



                SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1) 


                Output:



                201852    201852






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 30 '18 at 1:03









                NickNick

                27.1k111940




                27.1k111940

























                    0














                    Consider



                    SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
                    SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday


                    while 2018-01-06 seems to return 201801.



                    returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays






                    share|improve this answer
























                    • Thank you very much! How can I get the same "week-value" for both dates?

                      – itranger
                      Dec 30 '18 at 0:46
















                    0














                    Consider



                    SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
                    SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday


                    while 2018-01-06 seems to return 201801.



                    returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays






                    share|improve this answer
























                    • Thank you very much! How can I get the same "week-value" for both dates?

                      – itranger
                      Dec 30 '18 at 0:46














                    0












                    0








                    0







                    Consider



                    SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
                    SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday


                    while 2018-01-06 seems to return 201801.



                    returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays






                    share|improve this answer













                    Consider



                    SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
                    SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday


                    while 2018-01-06 seems to return 201801.



                    returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 30 '18 at 0:34









                    Barbaros ÖzhanBarbaros Özhan

                    12.8k71632




                    12.8k71632













                    • Thank you very much! How can I get the same "week-value" for both dates?

                      – itranger
                      Dec 30 '18 at 0:46



















                    • Thank you very much! How can I get the same "week-value" for both dates?

                      – itranger
                      Dec 30 '18 at 0:46

















                    Thank you very much! How can I get the same "week-value" for both dates?

                    – itranger
                    Dec 30 '18 at 0:46





                    Thank you very much! How can I get the same "week-value" for both dates?

                    – itranger
                    Dec 30 '18 at 0:46


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974375%2fyearweek-returns-different-results%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    iUo,Eev,5qiYyauvPs qieEY,ATIV7BO,9,UO x2bTcMr5G,qAm,N
                    1rkSA7lXPs1I64T69vlJLxM7,rg5TW,tBEanGKe8,AA9AgkrZXAq9,OjQA0vF5

                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas