Computing.Net > Forums > Programming > Batch not able to use modulus

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch not able to use modulus

Reply to Message Icon

Name: stroke6463
Date: August 15, 2006 at 12:54:03 Pacific
OS: XP PRO
CPU/Ram: idk
Comment:

I have a batch that checks daily for the month day and year. I have to change a file name to be -3 days on a monday to the previous fridays date. I have the months and years figured out but the problem is on a leap year it screws up my program. I just want the output to be 0 in 2008 confirming that it is a leap year. Here is an example:

set Year=06
set /a Leap=%test:~1,1%%4
echo %Leap%
The output is 6.

When I manually run that from the command line step by step it works perfectly but when I run it from a batch it doesn't see the % operator. Any ideas? Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: August 15, 2006 at 15:40:32 Pacific
Reply:

Hi
Don't know what %Test% is, you need the full year to test for a leap year.

Maybe this will work.

set Year=06
set /a Leap=%test:~1,1%%%4
echo %Leap%
The output is 6.

or something like this

@echo off
set Year=2006
set /a LeapYr=%Year%%%4
if %LeapYr%==0 (echo Leap Year) else (Echo Not A Leap Year)


0

Response Number 2
Name: Mechanix2Go
Date: August 16, 2006 at 00:08:46 Pacific
Reply:

Like dtech10, I dunno what %test% is.

But regardless, he's found the problem. A BAT 'strips' %, so you need one additional % within the BAT.


If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: stroke6463
Date: August 16, 2006 at 05:45:47 Pacific
Reply:

Thanks guys. Sorry the test was supposed to be Year.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch to dial multiple ph... Hide Another App's Proces...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch not able to use modulus

modify nslookup script to use batch www.computing.net/answers/programming/modify-nslookup-script-to-use-batch/15943.html

Copying favorites to map drive www.computing.net/answers/programming/copying-favorites-to-map-drive/13902.html

Form passing in php on winxp www.computing.net/answers/programming/form-passing-in-php-on-winxp/7097.html