Batch failure “numeric constants are decimal, hexadecimal or octal” when performing addition, why does it...
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
add a comment |
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
add a comment |
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
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
batch
asked Sep 19 '17 at 11:17
HenryHenry
103
103
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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.
@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
add a comment |
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=
add a comment |
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
andFOR
parameters. To treat a percent as a regular character,
double it:
%%
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
@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
add a comment |
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.
@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
add a comment |
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.
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.
edited Sep 19 '17 at 11:25
answered Sep 19 '17 at 11:21
Kamil MaciorowskiKamil Maciorowski
25.8k155678
25.8k155678
@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
add a comment |
@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
add a comment |
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=
add a comment |
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=
add a comment |
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=
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=
edited Dec 19 '18 at 11:29
zx485
879713
879713
answered Dec 19 '18 at 9:38
Jan van HultenJan van Hulten
111
111
add a comment |
add a comment |
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
andFOR
parameters. To treat a percent as a regular character,
double it:
%%
add a comment |
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
andFOR
parameters. To treat a percent as a regular character,
double it:
%%
add a comment |
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
andFOR
parameters. To treat a percent as a regular character,
double it:
%%
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
andFOR
parameters. To treat a percent as a regular character,
double it:
%%
answered Sep 19 '17 at 11:38
JosefZJosefZ
7,24041544
7,24041544
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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