Computing.Net > Forums > Disk Operating System > Batch File Variables Troubles

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 File Variables Troubles

Reply to Message Icon

Name: NBlock
Date: October 8, 2003 at 07:33:32 Pacific
OS: n/a
CPU/Ram: n/a
Comment:

I've got a batch file in which I'm having to manipulate
a few variables concerning dates. As the program
executes, it parses the date into individiual variables
such as month number (i.e. 09 for September, 10
for October, etc.). I need to know how to be able to
subtract one month from that variable but still have
it be two digits (i.e. 10 minus 1 be "09" rather than
"9"). Currently, the leading zero on months 01-09 is
lost when I make that subtraction.

Many thanks in advance!
N Block



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 8, 2003 at 08:57:32 Pacific
Reply:

I assume you are running your batch under Windows NT/2K/XP (an NT-kernel based system) as you stated about string parsing and arithmetic, operations not usually performed under Windows 9X/ME.

If so, after subtraction you have to test

If "%Month:~1,1%"=="" Set Month=0%Month%

and you get the vanished 0.

This works only under the previously reported operating systems. I hope this helps


0

Response Number 2
Name: IVO
Date: October 8, 2003 at 09:02:38 Pacific
Reply:

Obviously in my previous post substitute Month with your variable name!


0

Response Number 3
Name: NBlock
Date: October 8, 2003 at 11:33:51 Pacific
Reply:

Works like a charm. I am much obliged.

Nick Block


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


replace chacters in text ... Adding IP address through...



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch File Variables Troubles

Batch File Variables www.computing.net/answers/dos/batch-file-variables/7151.html

Batch File Variables www.computing.net/answers/dos/batch-file-variables/14203.html

Batch file variables www.computing.net/answers/dos/batch-file-variables/14215.html