Computing.Net > Forums > Programming > batch substract

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 substract

Reply to Message Icon

Name: javer
Date: October 7, 2007 at 02:20:03 Pacific
OS: xp
CPU/Ram: 435reg
Product: ertert
Comment:

Hi all, I need to make batch script that substract the time.
I've got this :

set rok = %date:~-4,2%
set month=%date:~-10,2%
set day=%date:~-7,2%
for /f "tokens=1-2 delims=: " %%a in ('%time%') do (
set hh=%%a
set mm=%%b)

and now I need to substract variable day
I tried set day = %day%-5 and so on, but nothing works.




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 7, 2007 at 03:27:30 Pacific
Reply:

To perform arithmetics on environment variables you have to use Set /A format (see Set /? to know more) so

Set /A day=%day%-5 or Set /A day-=5

without blanks before or after the = symbol.

The problem however is due to computing on date/time that is not a built-in facility. So subtracting 5 from current day may lead to a negative date (a Sci-Fi novel I love is "July, 32: the day never was" but that is Sci-Fi).


0

Response Number 2
Name: javer
Date: October 7, 2007 at 05:07:11 Pacific
Reply:

Thank you, I know about that problem and i've got no idea how to solve it using batch script. So I'm considering to write a small program with the output my date and time format. But the I don't know how to make something like pipe ("|") in unix. For example I need to create directory which name is another program output.

I tried: mkdir %myprogram.exe% but with no sucsses

Thanx Javer


0

Response Number 3
Name: IVO
Date: October 7, 2007 at 07:09:22 Pacific
Reply:

What you say is quite unclear and the command you posted has no meaning at all.

Starting from that I don't know which language you like to code in, but any programming language offers functions to create directory or its output to stdout can be directly "piped" to a batch statement to further parsing/processing.

The last issue is however far beyond this short note and requires a deep knowledge of NT advanced batch scripting.

By the way to perform date arithmetics is a hard work by batch, but not much easier by programming languages.


0

Response Number 4
Name: javer
Date: October 7, 2007 at 13:06:56 Pacific
Reply:

Ok i try to explain it. I want to make backup batch script that will backup something for last 5 days. I found there is a command xcopy that can do it. So now i need to code date arithmetics. It's impossible for me to write it like batch script becouse I'm writing script for the first time. But I'm able to write it in some other language for example C.

So I have written small program, which prints to stdout modified date(for example 2007__2_10__22_2). Actually I don't wanna create directory. I would like to set value of some variable to this output (2007__2_10__22_2). And i dont know how.....

I want batch script and not to code all things in C. Thank you

Javer


0

Response Number 5
Name: IVO
Date: October 7, 2007 at 13:21:43 Pacific
Reply:

Well, to set up a variable with the stdout generated by a program code the following statement in a batch (where JaverPG is your program)

For /F %%A in ('JaverPG') Do Set MyVar=%%A

Listen to me, however, you need more training in batch scripting.



0

Related Posts

See More



Response Number 6
Name: javer
Date: October 7, 2007 at 14:51:27 Pacific
Reply:

Thank you very much :)


0

Response Number 7
Name: ghostdog
Date: October 7, 2007 at 20:36:15 Pacific
Reply:

if this is for work, you might as well use a better language that supports such date manipulation. You can use tools like vbscript/perl/python etc. However, since vbscript is native to Windows, some examples of simple date arithmetic
[code]
N=Now
theDay=Day(N-5) '5 days ago
theMonth=Month(N-1) '1 month ago
WScript.Echo "The day 5 days ago is " , theDay
WScript.Echo "The month 1 month ago is ", theMonth
WScript.Echo DateAdd("d",1,Now) 'The date one day from now
WScript.Echo DateAdd("d",-5,Now) 'the date five days ago
[/code]


0

Sponsored Link
Ads by Google
Reply to Message Icon

Active Directory and VB.N... Creating Thread (operatin...



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 substract

Files Modified Batch... www.computing.net/answers/programming/files-modified-batch/16867.html

Batch file to count a specific character in a www.computing.net/answers/programming/batch-file-to-count-a-specific-character-in-a/19751.html

Collect Antivirus info via batch www.computing.net/answers/programming/collect-antivirus-info-via-batch/20104.html