Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SET command

Status
Not open for further replies.

RobNisbet

Programmer
Jul 10, 2001
22
0
0
GB
Hi
I have a little piece of a batch file which works out the number of last month...however I am struggling to get the set command to work properly to remove 1 from the number.
Anyone able to make it work ?
Thanks..

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do (
set MO=%%B
set Y=%%C
)
echo Month is %MO%
set /A M= ( %MO% -1)
echo Month is %M%
pause
 
Huh, as far as I tested your batch, it seems to work???
Result : MO=3 , M=2


Marc
[sub]If 'something' 'somewhere' gives 'some' error, expect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
Hi,
Thanks for responding ....but
I get a Missing Operard error, and M is blank.
Any ideas why ? (or an easier way of doing the whole thing?!)

Thanks !
 
Well, I cannot test it here, because ... it works here! Isn't that annoying ;-)
 
It sure is....
about the set command in isolation though ..
set /A %M= 8
works fine
set /A %M= (8+1) gives the error.

Is that the same with you ?

Cheers
 
You're not gonna believe it, but that also works here.

Try
set /A M= 8
set /A M= ( %M% +1)
echo Month is %M%

also

set /A M= 8+1
echo Month is %M%
 
Stranger still .. but resolved

set /A M= 8
set /A M= ( %M% +1)
echo Month is %M%
*this said invalid lala

set /A M= 8+1
echo Month is %M%
*but this worked

set /A M= 8
set /A M= %M% +1
*And this worked !!
which is the one I needed !

BUT when I put the string 08 from the date into M it doesnt like it.... any idea how to convert the string 08 into the number 8 ??

I am starting to think there must be an easier way to get the number of last month....??

Thanks..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top