Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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
Thanx Javer

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
Javer

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.

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]

![]() |
Active Directory and VB.N...
|
Creating Thread (operatin...
|

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