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

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.

::== runtoday.bat
@echo off
setLocal EnableDelayedExpansionset /p refDATE=enter date to compare in format: YYYYMMDD
call :now
if !refDATE! lss !today! echo don't run
if !refDATE! geq !today! echo rungoto :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 Qdebug < d.d > nul
del d.ddat
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

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?

if !refDATE! lss !today! goto :skip
if !refDATE! geq !today! myprog
:skip
=====================================
If at first you don't succeed, you're about average.M2

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?

"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

![]() |
![]() |
![]() |

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