0

I am getting invalid number.Numeric constants are either decimal(17),hexadecimal(0x11),or octal(021). It also keeps renaming it 20161201_2012312016 even though I am running now when it should be 20160801_20160831. I've pasted code. Thanks

@echo off

set FirstDay=01

set /a Month=%date:~4,2%-1
set Month=0%Month%
set Month=%Month:~-2%

set Year=%date:~10,4%

if %Month%==00 (
  set Month=12
  set /a Year=%Year%-1
)

if %Month%==01 set "LastDay=31" & goto foundate
if %Month%==02 set "LastDay=28" & goto foundate
if %Month%==03 set "LastDay=31" & goto foundate
if %Month%==04 set "LastDay=30" & goto foundate
if %Month%==05 set "LastDay=31" & goto foundate
if %Month%==06 set "LastDay=30" & goto foundate
if %Month%==07 set "LastDay=31" & goto foundate
if %Month%==08 set "LastDay=31" & goto foundate
if %Month%==09 set "LastDay=30" & goto foundate
if %Month%==10 set "LastDay=31" & goto foundate
if %Month%==11 set "LastDay=30" & goto foundate
if %Month%==12 set "LastDay=31" & goto foundate



:foundate
echo The year is: %Year%
echo The month is: %Month%
echo First day of this month is: %FirstDay%
echo Last day of this month is: %LastDay%

set FileDir=Z:\"EpicCare Reports"\Reports_Team\Scheduled_Reports_Output \PreUHC\


set fileext=.txt
set Ifile=CPT_000318_
set ofile=%ifile%%Year%%Month%%FirstDay%_%Year%%Month%%Lastday%%fileext%

echo Output Filename: %ofile%
ren %FileDir%%ifile%.txt %ofile% 

  move /Y %FileDir%%ofile% Z:\"EpicCare Reports"\Reports_Team\Scheduled_Reports_Output\UHC\
tjonas
  • 21
  • 1
  • 3

1 Answers1

0

Problem is with leading zeros, which are interpreted as soon as you try to perform calculations:

set month=08
set /A month+=1

will give the exact error you're reporting because 08 is interpreted as octal number, and invalid since 8 cannot be an octal digit.

Fixable in many ways. My personal one:

set month=%month:08=8%
set month=%month:09=9%
set /A month+=1
set month=%month:8=08%
set month=%month:9=09%
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • What can I do to fix it? Sorry I'm just learning. – tjonas Sep 07 '16 at 14:37
  • follow the link (question was marked as duplicate but first you would have to understand what was the problem), it fixes it nicely with some trick (add 1 then substract 100, – Jean-François Fabre Sep 07 '16 at 14:38
  • I need the leading zero, will that keep it? – tjonas Sep 07 '16 at 14:43
  • yes, as soon as you use `set /A`. But it's really fixable once you know it. – Jean-François Fabre Sep 07 '16 at 14:44
  • I've added but it still gives me the invalid number error and renames it wrong. What am i doing wrong? ' set /a Month=%date:~4,2%-1 set month=%month:01=1% set month=%month:02=2% set month=%month:03=3% set month=%month:04=4% set month=%month:05=5% set month=%month:06=6% set month=%month:07=7% set month=%month:08=8% set month=%month:09=9% set month=%month:10=10% set month=%month:11=11% set month=%month:12=12% set Month=%Month:~-2%' – tjonas Sep 07 '16 at 14:50
  • @tjonas, do not post that much code in a comment. If you have changed your code, then you need to edit your original question. – Squashman Sep 07 '16 at 15:19
  • just replace 8 by 08 and 9 by 09 in the end (you don't need to do it for the values 0=>7 because octal = decimal. – Jean-François Fabre Sep 07 '16 at 15:32
  • I'm not sure what you mean? It isn't working at all now. – tjonas Sep 07 '16 at 15:41
  • see my last edit: remove zero, add, add zero. – Jean-François Fabre Sep 07 '16 at 15:50