Date Command Gives Wrong Week Number for Dec 31











up vote
19
down vote

favorite












When I try to get the week number for Dec 31, it returns 1. When I get the week number for Dec 30, I get 52 --- which is what I would expect. The day Monday is correct. This is on a RPI running Ubuntu.



$ date -d "2018-12-30T1:58:55" +"%V%a"

52Sun

$ date -d "2018-12-31T1:58:55" +"%V%a"

01Mon


Same issue without time string



$ date -d "2018-12-31" +"%V%a"

01Mon









share|improve this question




















  • 9




    "Date Command Gives Wrong Week Number for Dec 31" – "Wrong" according to which specification? Is the specification you are using the same one that the manual for date says it is using?
    – Jörg W Mittag
    Nov 15 at 22:41






  • 2




    Excel week number inconsistent results, Excel weeknum function returns wrong week, UI calendar shows wrong week number
    – phuclv
    Nov 16 at 6:27






  • 2




    You might be interested in Why does the MonthCalendar control show the wrong week numbers in Romania? The blog post is about Windows, but the issue being discussed is general (and seems to be the same as what you are encountering).
    – a CVn
    Nov 16 at 10:25








  • 1




    "The computer must be wrong, because I obviously didn't make a mistake!" reminds me of when I complained that the FORTRAN IV compiler must have a bug, because my first simple program couldn't have any errors...
    – RonJohn
    Nov 17 at 5:23















up vote
19
down vote

favorite












When I try to get the week number for Dec 31, it returns 1. When I get the week number for Dec 30, I get 52 --- which is what I would expect. The day Monday is correct. This is on a RPI running Ubuntu.



$ date -d "2018-12-30T1:58:55" +"%V%a"

52Sun

$ date -d "2018-12-31T1:58:55" +"%V%a"

01Mon


Same issue without time string



$ date -d "2018-12-31" +"%V%a"

01Mon









share|improve this question




















  • 9




    "Date Command Gives Wrong Week Number for Dec 31" – "Wrong" according to which specification? Is the specification you are using the same one that the manual for date says it is using?
    – Jörg W Mittag
    Nov 15 at 22:41






  • 2




    Excel week number inconsistent results, Excel weeknum function returns wrong week, UI calendar shows wrong week number
    – phuclv
    Nov 16 at 6:27






  • 2




    You might be interested in Why does the MonthCalendar control show the wrong week numbers in Romania? The blog post is about Windows, but the issue being discussed is general (and seems to be the same as what you are encountering).
    – a CVn
    Nov 16 at 10:25








  • 1




    "The computer must be wrong, because I obviously didn't make a mistake!" reminds me of when I complained that the FORTRAN IV compiler must have a bug, because my first simple program couldn't have any errors...
    – RonJohn
    Nov 17 at 5:23













up vote
19
down vote

favorite









up vote
19
down vote

favorite











When I try to get the week number for Dec 31, it returns 1. When I get the week number for Dec 30, I get 52 --- which is what I would expect. The day Monday is correct. This is on a RPI running Ubuntu.



$ date -d "2018-12-30T1:58:55" +"%V%a"

52Sun

$ date -d "2018-12-31T1:58:55" +"%V%a"

01Mon


Same issue without time string



$ date -d "2018-12-31" +"%V%a"

01Mon









share|improve this question















When I try to get the week number for Dec 31, it returns 1. When I get the week number for Dec 30, I get 52 --- which is what I would expect. The day Monday is correct. This is on a RPI running Ubuntu.



$ date -d "2018-12-30T1:58:55" +"%V%a"

52Sun

$ date -d "2018-12-31T1:58:55" +"%V%a"

01Mon


Same issue without time string



$ date -d "2018-12-31" +"%V%a"

01Mon






linux command-line date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 20:24









Jesse_b

11.4k23063




11.4k23063










asked Nov 15 at 20:22









George Shafer

1104




1104








  • 9




    "Date Command Gives Wrong Week Number for Dec 31" – "Wrong" according to which specification? Is the specification you are using the same one that the manual for date says it is using?
    – Jörg W Mittag
    Nov 15 at 22:41






  • 2




    Excel week number inconsistent results, Excel weeknum function returns wrong week, UI calendar shows wrong week number
    – phuclv
    Nov 16 at 6:27






  • 2




    You might be interested in Why does the MonthCalendar control show the wrong week numbers in Romania? The blog post is about Windows, but the issue being discussed is general (and seems to be the same as what you are encountering).
    – a CVn
    Nov 16 at 10:25








  • 1




    "The computer must be wrong, because I obviously didn't make a mistake!" reminds me of when I complained that the FORTRAN IV compiler must have a bug, because my first simple program couldn't have any errors...
    – RonJohn
    Nov 17 at 5:23














  • 9




    "Date Command Gives Wrong Week Number for Dec 31" – "Wrong" according to which specification? Is the specification you are using the same one that the manual for date says it is using?
    – Jörg W Mittag
    Nov 15 at 22:41






  • 2




    Excel week number inconsistent results, Excel weeknum function returns wrong week, UI calendar shows wrong week number
    – phuclv
    Nov 16 at 6:27






  • 2




    You might be interested in Why does the MonthCalendar control show the wrong week numbers in Romania? The blog post is about Windows, but the issue being discussed is general (and seems to be the same as what you are encountering).
    – a CVn
    Nov 16 at 10:25








  • 1




    "The computer must be wrong, because I obviously didn't make a mistake!" reminds me of when I complained that the FORTRAN IV compiler must have a bug, because my first simple program couldn't have any errors...
    – RonJohn
    Nov 17 at 5:23








9




9




"Date Command Gives Wrong Week Number for Dec 31" – "Wrong" according to which specification? Is the specification you are using the same one that the manual for date says it is using?
– Jörg W Mittag
Nov 15 at 22:41




"Date Command Gives Wrong Week Number for Dec 31" – "Wrong" according to which specification? Is the specification you are using the same one that the manual for date says it is using?
– Jörg W Mittag
Nov 15 at 22:41




2




2




Excel week number inconsistent results, Excel weeknum function returns wrong week, UI calendar shows wrong week number
– phuclv
Nov 16 at 6:27




Excel week number inconsistent results, Excel weeknum function returns wrong week, UI calendar shows wrong week number
– phuclv
Nov 16 at 6:27




2




2




You might be interested in Why does the MonthCalendar control show the wrong week numbers in Romania? The blog post is about Windows, but the issue being discussed is general (and seems to be the same as what you are encountering).
– a CVn
Nov 16 at 10:25






You might be interested in Why does the MonthCalendar control show the wrong week numbers in Romania? The blog post is about Windows, but the issue being discussed is general (and seems to be the same as what you are encountering).
– a CVn
Nov 16 at 10:25






1




1




"The computer must be wrong, because I obviously didn't make a mistake!" reminds me of when I complained that the FORTRAN IV compiler must have a bug, because my first simple program couldn't have any errors...
– RonJohn
Nov 17 at 5:23




"The computer must be wrong, because I obviously didn't make a mistake!" reminds me of when I complained that the FORTRAN IV compiler must have a bug, because my first simple program couldn't have any errors...
– RonJohn
Nov 17 at 5:23










2 Answers
2






active

oldest

votes

















up vote
49
down vote



accepted










This is giving you the ISO week which begins on a Monday.




The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 (last revised in 2004) and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.








An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term.



Weeks start with Monday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.






If you want to show 12/31 as week 52, you should use %U, which does not use the ISO standard:



$ date -d "2018-12-31T1:58:55" +"%V%a"
01Mon
$ date -d "2018-12-31T1:58:55" +"%U%a"
52Mon





share|improve this answer























  • Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
    – George Shafer
    Nov 16 at 21:10


















up vote
3
down vote













The definition of the week number is different between Europe and the USA, probably ISO versus ANSI standards. This may be related to a week being Sunday--Saturday or Monday--Sunday, and this again may be related to the Jewish versus Christian definition of the Lord's Day (Sabbath vs Sunday).



For Europe, week number 1 contains the first Thursday in January, and thus it contains a minimum of 4 days (i.e. a majority) belonging to the new year (Thu-Fri-Sat-Sun).



Anyway, in such years when ALL (!!) week numbers are +/- 1 different between Europe and the USA this gives great fun with setting schedules in multi-national companies. :-)






share|improve this answer








New contributor




StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    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',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f482032%2fdate-command-gives-wrong-week-number-for-dec-31%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








    up vote
    49
    down vote



    accepted










    This is giving you the ISO week which begins on a Monday.




    The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 (last revised in 2004) and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.








    An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term.



    Weeks start with Monday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.






    If you want to show 12/31 as week 52, you should use %U, which does not use the ISO standard:



    $ date -d "2018-12-31T1:58:55" +"%V%a"
    01Mon
    $ date -d "2018-12-31T1:58:55" +"%U%a"
    52Mon





    share|improve this answer























    • Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
      – George Shafer
      Nov 16 at 21:10















    up vote
    49
    down vote



    accepted










    This is giving you the ISO week which begins on a Monday.




    The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 (last revised in 2004) and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.








    An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term.



    Weeks start with Monday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.






    If you want to show 12/31 as week 52, you should use %U, which does not use the ISO standard:



    $ date -d "2018-12-31T1:58:55" +"%V%a"
    01Mon
    $ date -d "2018-12-31T1:58:55" +"%U%a"
    52Mon





    share|improve this answer























    • Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
      – George Shafer
      Nov 16 at 21:10













    up vote
    49
    down vote



    accepted







    up vote
    49
    down vote



    accepted






    This is giving you the ISO week which begins on a Monday.




    The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 (last revised in 2004) and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.








    An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term.



    Weeks start with Monday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.






    If you want to show 12/31 as week 52, you should use %U, which does not use the ISO standard:



    $ date -d "2018-12-31T1:58:55" +"%V%a"
    01Mon
    $ date -d "2018-12-31T1:58:55" +"%U%a"
    52Mon





    share|improve this answer














    This is giving you the ISO week which begins on a Monday.




    The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 (last revised in 2004) and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.








    An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term.



    Weeks start with Monday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.






    If you want to show 12/31 as week 52, you should use %U, which does not use the ISO standard:



    $ date -d "2018-12-31T1:58:55" +"%V%a"
    01Mon
    $ date -d "2018-12-31T1:58:55" +"%U%a"
    52Mon






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 17 at 12:43









    Jeff Schaller

    36.3k952119




    36.3k952119










    answered Nov 15 at 20:29









    Jesse_b

    11.4k23063




    11.4k23063












    • Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
      – George Shafer
      Nov 16 at 21:10


















    • Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
      – George Shafer
      Nov 16 at 21:10
















    Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
    – George Shafer
    Nov 16 at 21:10




    Thanks. That is what I was looking for. I used a much more convoluted method with the cal command.
    – George Shafer
    Nov 16 at 21:10












    up vote
    3
    down vote













    The definition of the week number is different between Europe and the USA, probably ISO versus ANSI standards. This may be related to a week being Sunday--Saturday or Monday--Sunday, and this again may be related to the Jewish versus Christian definition of the Lord's Day (Sabbath vs Sunday).



    For Europe, week number 1 contains the first Thursday in January, and thus it contains a minimum of 4 days (i.e. a majority) belonging to the new year (Thu-Fri-Sat-Sun).



    Anyway, in such years when ALL (!!) week numbers are +/- 1 different between Europe and the USA this gives great fun with setting schedules in multi-national companies. :-)






    share|improve this answer








    New contributor




    StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      3
      down vote













      The definition of the week number is different between Europe and the USA, probably ISO versus ANSI standards. This may be related to a week being Sunday--Saturday or Monday--Sunday, and this again may be related to the Jewish versus Christian definition of the Lord's Day (Sabbath vs Sunday).



      For Europe, week number 1 contains the first Thursday in January, and thus it contains a minimum of 4 days (i.e. a majority) belonging to the new year (Thu-Fri-Sat-Sun).



      Anyway, in such years when ALL (!!) week numbers are +/- 1 different between Europe and the USA this gives great fun with setting schedules in multi-national companies. :-)






      share|improve this answer








      New contributor




      StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        3
        down vote










        up vote
        3
        down vote









        The definition of the week number is different between Europe and the USA, probably ISO versus ANSI standards. This may be related to a week being Sunday--Saturday or Monday--Sunday, and this again may be related to the Jewish versus Christian definition of the Lord's Day (Sabbath vs Sunday).



        For Europe, week number 1 contains the first Thursday in January, and thus it contains a minimum of 4 days (i.e. a majority) belonging to the new year (Thu-Fri-Sat-Sun).



        Anyway, in such years when ALL (!!) week numbers are +/- 1 different between Europe and the USA this gives great fun with setting schedules in multi-national companies. :-)






        share|improve this answer








        New contributor




        StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        The definition of the week number is different between Europe and the USA, probably ISO versus ANSI standards. This may be related to a week being Sunday--Saturday or Monday--Sunday, and this again may be related to the Jewish versus Christian definition of the Lord's Day (Sabbath vs Sunday).



        For Europe, week number 1 contains the first Thursday in January, and thus it contains a minimum of 4 days (i.e. a majority) belonging to the new year (Thu-Fri-Sat-Sun).



        Anyway, in such years when ALL (!!) week numbers are +/- 1 different between Europe and the USA this gives great fun with setting schedules in multi-national companies. :-)







        share|improve this answer








        New contributor




        StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Nov 16 at 12:17









        StessenJ

        1471




        1471




        New contributor




        StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        StessenJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482032%2fdate-command-gives-wrong-week-number-for-dec-31%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







            Popular posts from this blog

            Список кардиналов, возведённых папой римским Каликстом III

            Deduzione

            Mysql.sock missing - “Can't connect to local MySQL server through socket”