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).
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
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.
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
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]
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE