batch file date issue- mm seen as octal

Microsoft Windows server 2008 standard -...
December 16, 2010 at 01:23:03
Specs: Windows Vista
Hi,
I've written a batch file to change the system date forward by 1 month on Win2008. Its for some testing I'm doing. However when its gets to september I get the following error

Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).

I know its because 08 and 09 are seen by DOS as octal numbers but Im pretty new to DOS and dont know how to fix it.

Here is my code, any assistance is much appreciated!

@echo off
set /a d=%date:~0,2%
set /a m=%date:~3,2%
set /a y=%date:~6,4%

:loop
set /a m+=1

if %m% gtr 12 (
set m=1
set /a y+=1
)
)
date %d%/%m%/%y%

echo %d%/%m%/%y%


See More: batch file date issue- mm seen as octal

Report •


#1
December 16, 2010 at 02:48:21
Edit:Some clarification / fixes.


All you have to do about the octal is prefix a "1" subtract and it later.


You can't really trust the date variable, but anyway....


Your logic also doesn't account for the 29th,30th and 31st not being available in certain months.

dd mm yyyy  - dd mm yyyy (not available)

29 01 2010  - 29 02 2010
30 01 2010 - 30 02 2010
31 01 2010 - 31 02 2010

It will be a very common problem in fact:

January -> February
March -> April
May -> June
August -> September
October -> November

All could fall from the same issue and it is still the same below. I'm not sure of how you would even want to deal with it (roll over again to the first? Use the last day?).

@echo off
set d=%date:~0,2%
set m=%date:~3,2%
set y=%date:~6,4%

:loop
set /a m=1%m% + 1

if %m% gtr 112 (
    set m=01
    set /a y+=1
) else set m=%m:~1%

date %d%/%m%/%y%

echo %d%/%m%/%y%


Report •

#2
December 16, 2010 at 04:17:15
that worked perfectly, thanks!

I dont have to worry about the day as the testing im doing just needs to be done 1 day a month eg
16 dec 2010
16 jan 2011
16 feb 2011

thanks again.


Report •

Related Solutions


Ask Question