Batch failure “numeric constants are decimal, hexadecimal or octal” when performing addition, why does it...












0















for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set month=%dt:~4,2%
set day=%dt:~6,2%
set /a rday=%day%+470
set /a rmonth+%month%+590
echo %rmonth%
echo %rday%
pause


What I am trying to do, is find the day and the month, and add numbers to their value. For the month, I'm adding 590, and for the day, I'm adding 470.



It works fine for the day, but for the month, it does not work, and I receive the error "Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021)."



I am by no means a programmer, or knowledgeable in batch. I have found the code for extracting the day and the month on the internet, the only thing I've done myself is the last part, and it does not seem to work properly. I assume there must be a simple fix.










share|improve this question



























    0















    for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
    set month=%dt:~4,2%
    set day=%dt:~6,2%
    set /a rday=%day%+470
    set /a rmonth+%month%+590
    echo %rmonth%
    echo %rday%
    pause


    What I am trying to do, is find the day and the month, and add numbers to their value. For the month, I'm adding 590, and for the day, I'm adding 470.



    It works fine for the day, but for the month, it does not work, and I receive the error "Invalid number. Numeric constants are either decimal (17),
    hexadecimal (0x11), or octal (021)."



    I am by no means a programmer, or knowledgeable in batch. I have found the code for extracting the day and the month on the internet, the only thing I've done myself is the last part, and it does not seem to work properly. I assume there must be a simple fix.










    share|improve this question

























      0












      0








      0








      for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
      set month=%dt:~4,2%
      set day=%dt:~6,2%
      set /a rday=%day%+470
      set /a rmonth+%month%+590
      echo %rmonth%
      echo %rday%
      pause


      What I am trying to do, is find the day and the month, and add numbers to their value. For the month, I'm adding 590, and for the day, I'm adding 470.



      It works fine for the day, but for the month, it does not work, and I receive the error "Invalid number. Numeric constants are either decimal (17),
      hexadecimal (0x11), or octal (021)."



      I am by no means a programmer, or knowledgeable in batch. I have found the code for extracting the day and the month on the internet, the only thing I've done myself is the last part, and it does not seem to work properly. I assume there must be a simple fix.










      share|improve this question














      for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
      set month=%dt:~4,2%
      set day=%dt:~6,2%
      set /a rday=%day%+470
      set /a rmonth+%month%+590
      echo %rmonth%
      echo %rday%
      pause


      What I am trying to do, is find the day and the month, and add numbers to their value. For the month, I'm adding 590, and for the day, I'm adding 470.



      It works fine for the day, but for the month, it does not work, and I receive the error "Invalid number. Numeric constants are either decimal (17),
      hexadecimal (0x11), or octal (021)."



      I am by no means a programmer, or knowledgeable in batch. I have found the code for extracting the day and the month on the internet, the only thing I've done myself is the last part, and it does not seem to work properly. I assume there must be a simple fix.







      batch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 19 '17 at 11:17









      HenryHenry

      103




      103






















          3 Answers
          3






          active

          oldest

          votes


















          0














          It means 01 or 07 would be interpreted as octal number because of leading 0. It's September and 09 is not a valid octal number.



          A workaround could be



          set /a rmonth+1%month%+490


          but this looks like an ugly hack. I will gladly upvote another answer with the right solution.






          share|improve this answer


























          • @Vlad Yes, I think the day will not always work either.

            – Kamil Maciorowski
            Sep 19 '17 at 11:27











          • I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

            – Henry
            Sep 19 '17 at 11:28



















          1














          I had this problem, while extracting day and month from a date string.

          Adding a preceding zero to a %VALUE% in the 1..9 range raised the error.



          My solution was something like this:



          rem -- demo starts with a digit less than 10 but more than octal 7
          set VALUE=9
          rem -- add value to 100
          set /a NEWVALUE=%VALUE%+100
          rem -- no calculation but string manipulation : strip all but last two digits
          set VALUE=%NEWVALUE:~-2%
          rem -- digital environments too should be kept clean ;)
          set NEWVALUE=





          share|improve this answer

































            0














            Apply % Modulus operator as follows:



            for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
            set month=%dt:~4,2%
            set day=%dt:~6,2%
            set /a rday=1%day%%%100+470
            rem ↑ ↑↑
            set /a rmonth=1%month%%%100+590
            rem ↑ ↑↑
            echo %rmonth%
            echo %rday%
            pause


            Note that you need to double % percent sign in a batch script (read Escaping Percents):




            The % character has a special meaning for command line parameters
            and FOR parameters. To treat a percent as a regular character,
            double it:



            %%






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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%2fsuperuser.com%2fquestions%2f1251736%2fbatch-failure-numeric-constants-are-decimal-hexadecimal-or-octal-when-perform%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              It means 01 or 07 would be interpreted as octal number because of leading 0. It's September and 09 is not a valid octal number.



              A workaround could be



              set /a rmonth+1%month%+490


              but this looks like an ugly hack. I will gladly upvote another answer with the right solution.






              share|improve this answer


























              • @Vlad Yes, I think the day will not always work either.

                – Kamil Maciorowski
                Sep 19 '17 at 11:27











              • I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

                – Henry
                Sep 19 '17 at 11:28
















              0














              It means 01 or 07 would be interpreted as octal number because of leading 0. It's September and 09 is not a valid octal number.



              A workaround could be



              set /a rmonth+1%month%+490


              but this looks like an ugly hack. I will gladly upvote another answer with the right solution.






              share|improve this answer


























              • @Vlad Yes, I think the day will not always work either.

                – Kamil Maciorowski
                Sep 19 '17 at 11:27











              • I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

                – Henry
                Sep 19 '17 at 11:28














              0












              0








              0







              It means 01 or 07 would be interpreted as octal number because of leading 0. It's September and 09 is not a valid octal number.



              A workaround could be



              set /a rmonth+1%month%+490


              but this looks like an ugly hack. I will gladly upvote another answer with the right solution.






              share|improve this answer















              It means 01 or 07 would be interpreted as octal number because of leading 0. It's September and 09 is not a valid octal number.



              A workaround could be



              set /a rmonth+1%month%+490


              but this looks like an ugly hack. I will gladly upvote another answer with the right solution.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Sep 19 '17 at 11:25

























              answered Sep 19 '17 at 11:21









              Kamil MaciorowskiKamil Maciorowski

              25.6k155578




              25.6k155578













              • @Vlad Yes, I think the day will not always work either.

                – Kamil Maciorowski
                Sep 19 '17 at 11:27











              • I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

                – Henry
                Sep 19 '17 at 11:28



















              • @Vlad Yes, I think the day will not always work either.

                – Kamil Maciorowski
                Sep 19 '17 at 11:27











              • I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

                – Henry
                Sep 19 '17 at 11:28

















              @Vlad Yes, I think the day will not always work either.

              – Kamil Maciorowski
              Sep 19 '17 at 11:27





              @Vlad Yes, I think the day will not always work either.

              – Kamil Maciorowski
              Sep 19 '17 at 11:27













              I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

              – Henry
              Sep 19 '17 at 11:28





              I tested your solution, and it can work. It ended up with 599, which is a hundred days more than it should, but it's easy to subtract a hundred from the total value and receive the actual value. Thanks!

              – Henry
              Sep 19 '17 at 11:28













              1














              I had this problem, while extracting day and month from a date string.

              Adding a preceding zero to a %VALUE% in the 1..9 range raised the error.



              My solution was something like this:



              rem -- demo starts with a digit less than 10 but more than octal 7
              set VALUE=9
              rem -- add value to 100
              set /a NEWVALUE=%VALUE%+100
              rem -- no calculation but string manipulation : strip all but last two digits
              set VALUE=%NEWVALUE:~-2%
              rem -- digital environments too should be kept clean ;)
              set NEWVALUE=





              share|improve this answer






























                1














                I had this problem, while extracting day and month from a date string.

                Adding a preceding zero to a %VALUE% in the 1..9 range raised the error.



                My solution was something like this:



                rem -- demo starts with a digit less than 10 but more than octal 7
                set VALUE=9
                rem -- add value to 100
                set /a NEWVALUE=%VALUE%+100
                rem -- no calculation but string manipulation : strip all but last two digits
                set VALUE=%NEWVALUE:~-2%
                rem -- digital environments too should be kept clean ;)
                set NEWVALUE=





                share|improve this answer




























                  1












                  1








                  1







                  I had this problem, while extracting day and month from a date string.

                  Adding a preceding zero to a %VALUE% in the 1..9 range raised the error.



                  My solution was something like this:



                  rem -- demo starts with a digit less than 10 but more than octal 7
                  set VALUE=9
                  rem -- add value to 100
                  set /a NEWVALUE=%VALUE%+100
                  rem -- no calculation but string manipulation : strip all but last two digits
                  set VALUE=%NEWVALUE:~-2%
                  rem -- digital environments too should be kept clean ;)
                  set NEWVALUE=





                  share|improve this answer















                  I had this problem, while extracting day and month from a date string.

                  Adding a preceding zero to a %VALUE% in the 1..9 range raised the error.



                  My solution was something like this:



                  rem -- demo starts with a digit less than 10 but more than octal 7
                  set VALUE=9
                  rem -- add value to 100
                  set /a NEWVALUE=%VALUE%+100
                  rem -- no calculation but string manipulation : strip all but last two digits
                  set VALUE=%NEWVALUE:~-2%
                  rem -- digital environments too should be kept clean ;)
                  set NEWVALUE=






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 19 '18 at 11:29









                  zx485

                  826613




                  826613










                  answered Dec 19 '18 at 9:38









                  Jan van HultenJan van Hulten

                  111




                  111























                      0














                      Apply % Modulus operator as follows:



                      for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
                      set month=%dt:~4,2%
                      set day=%dt:~6,2%
                      set /a rday=1%day%%%100+470
                      rem ↑ ↑↑
                      set /a rmonth=1%month%%%100+590
                      rem ↑ ↑↑
                      echo %rmonth%
                      echo %rday%
                      pause


                      Note that you need to double % percent sign in a batch script (read Escaping Percents):




                      The % character has a special meaning for command line parameters
                      and FOR parameters. To treat a percent as a regular character,
                      double it:



                      %%






                      share|improve this answer




























                        0














                        Apply % Modulus operator as follows:



                        for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
                        set month=%dt:~4,2%
                        set day=%dt:~6,2%
                        set /a rday=1%day%%%100+470
                        rem ↑ ↑↑
                        set /a rmonth=1%month%%%100+590
                        rem ↑ ↑↑
                        echo %rmonth%
                        echo %rday%
                        pause


                        Note that you need to double % percent sign in a batch script (read Escaping Percents):




                        The % character has a special meaning for command line parameters
                        and FOR parameters. To treat a percent as a regular character,
                        double it:



                        %%






                        share|improve this answer


























                          0












                          0








                          0







                          Apply % Modulus operator as follows:



                          for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
                          set month=%dt:~4,2%
                          set day=%dt:~6,2%
                          set /a rday=1%day%%%100+470
                          rem ↑ ↑↑
                          set /a rmonth=1%month%%%100+590
                          rem ↑ ↑↑
                          echo %rmonth%
                          echo %rday%
                          pause


                          Note that you need to double % percent sign in a batch script (read Escaping Percents):




                          The % character has a special meaning for command line parameters
                          and FOR parameters. To treat a percent as a regular character,
                          double it:



                          %%






                          share|improve this answer













                          Apply % Modulus operator as follows:



                          for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
                          set month=%dt:~4,2%
                          set day=%dt:~6,2%
                          set /a rday=1%day%%%100+470
                          rem ↑ ↑↑
                          set /a rmonth=1%month%%%100+590
                          rem ↑ ↑↑
                          echo %rmonth%
                          echo %rday%
                          pause


                          Note that you need to double % percent sign in a batch script (read Escaping Percents):




                          The % character has a special meaning for command line parameters
                          and FOR parameters. To treat a percent as a regular character,
                          double it:



                          %%







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 19 '17 at 11:38









                          JosefZJosefZ

                          7,22041544




                          7,22041544






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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%2fsuperuser.com%2fquestions%2f1251736%2fbatch-failure-numeric-constants-are-decimal-hexadecimal-or-octal-when-perform%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

                              Plaza Victoria

                              In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                              How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...