Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

batch substract

Original Message
Name: javer
Date: October 7, 2007 at 02:20:03 Pacific
Subject: batch substract
OS: xp
CPU/Ram: 435reg
Model/Manufacturer: 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.



Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: October 7, 2007 at 03:27:30 Pacific
Subject: batch substract
Reply: (edit)
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).


Report Offensive Follow Up For Removal

Response Number 2
Name: javer
Date: October 7, 2007 at 05:07:11 Pacific
Subject: batch substract
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 3
Name: IVO
Date: October 7, 2007 at 07:09:22 Pacific
Subject: batch substract
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 4
Name: javer
Date: October 7, 2007 at 13:06:56 Pacific
Subject: batch substract
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 5
Name: IVO
Date: October 7, 2007 at 13:21:43 Pacific
Subject: batch substract
Reply: (edit)
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.



Report Offensive Follow Up For Removal


Response Number 6
Name: javer
Date: October 7, 2007 at 14:51:27 Pacific
Subject: batch substract
Reply: (edit)
Thank you very much :)

Report Offensive Follow Up For Removal

Response Number 7
Name: ghostdog
Date: October 7, 2007 at 20:36:15 Pacific
Subject: batch substract
Reply: (edit)
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]

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: batch substract

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


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

All content ©1996-2007 Computing.Net, LLC