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

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

Reply to Message Icon

Name: paulvan2
Date: March 22, 2007 at 18:52:15 Pacific
OS: XP
CPU/Ram: 2 Gig Ram
Product: 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?



Sponsored Link
Ads by Google

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

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.


0

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

::== 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



0

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

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?


0

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

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


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

M2



0

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

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?


0

Related Posts

See More



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

"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



0

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

Thank you very much


0

Sponsored Link
Ads by Google
Reply to Message Icon






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

Batch file xcopy based on date www.computing.net/answers/programming/batch-file-xcopy-based-on-date/15692.html

Small batch file/scripting program www.computing.net/answers/programming/small-batch-filescripting-program/2353.html

Batch file to append created date www.computing.net/answers/programming/batch-file-to-append-created-date/14993.html