Computing.Net > Forums > Programming > Batch File Exe Program on Date

Batch File Exe Program on Date

Reply to Message Icon

Original Message
Name: paulvan2
Date: March 22, 2007 at 18:52:15 Pacific
Subject: Batch File Exe Program on Date
OS: XP
CPU/Ram: 2 Gig Ram
Model/Manufacturer: Dell
Comment:

I am very new to Batch file writing and have spent several hours on google, so I am turning to the experts. What syntex do I use in a batch file to check the current system date and then if date is equal to or greater than a certain date then execute this program with these parameters and if not equal to or greater than this, then skip the program and parameters and continue with the rest of the batch file?


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: March 23, 2007 at 04:00:23 Pacific
Reply: (edit)

Batch scripting language has no builtin functions to perform arithmetic computations on time and date. A lot of work is required due to substring manipulation.

Better you use a script language as Perl; anyway thesystem curent date is stored in the system variable Date; its format is related to country's conventions.


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: March 23, 2007 at 05:36:09 Pacific
Reply: (edit)

::== runtoday.bat
@echo off
setLocal EnableDelayedExpansion

set /p refDATE=enter date to compare in format: YYYYMMDD
call :now
if !refDATE! lss !today! echo don't run
if !refDATE! geq !today! echo run

goto :eof

:now
:: use debug/BIOS to get DATE into vars

::==
@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%
set today=%year%%month%%dat%
echo Today is %today%
for %%c in (day month year dat) do del %%c.com
::== done


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: paulvan2
Date: March 23, 2007 at 11:00:22 Pacific
Reply: (edit)

As I stated I am a newbee. If it is not asking too much could you point out the variables I need to change to input specified date to run the program and where then do I place the program name with my commands. I was going to place this within a batch file I have already created so I wanted it to jump past the call for the program if the desired date was not equal to or great than specified. I believe the example calls to go to end of file if the arguemnt is not satisfied. Is that correct?


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: March 23, 2007 at 12:30:53 Pacific
Reply: (edit)

if !refDATE! lss !today! goto :skip
if !refDATE! geq !today! myprog
:skip


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: paulvan2
Date: March 23, 2007 at 13:48:46 Pacific
Reply: (edit)

so do I put the :skip just before where I want the batch file to continue on to if the specified date is not reached which would be at the end of your file and then do I no longer need the ::== done statement?


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: March 23, 2007 at 14:33:39 Pacific
Reply: (edit)

"so do I put the :skip just before where I want the batch file to continue on to if the specified date is not reached"

yes

"then do I no longer need the ::== done statement?"

that's just a 'label'


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 7
Name: paulvan2
Date: March 25, 2007 at 18:39:56 Pacific
Reply: (edit)

Thank you very much


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 File Exe Program on Date

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge