Need IF statement to check if today is Monday, Wednesday or Friday

  • Thread starter Lawrence M. Seldin, CMC, CPC
  • Start date
L

Lawrence M. Seldin, CMC, CPC

I have Win2k with SP4. In the Scheduler I have a bat script that "calls 4 exe programs". However,
they are taking longer to complete. I don't want to break the script into more than one script.


I have 4 "call exe" statements. I want 2 of them to run on Monday, Wednesday and Friday.
I want the other 2, to run on Tuesday and Thursday.

Something like:

If today is Monday or Wednesday or Friday
begin
call A.exe
call B.exe
end

If today is Tueday or Thursday
begin
call C.exe
call D.exe
end

However, I only want to create a single bat file for both if statements. I already have a Task, in
the task scheduler that runs daily.

PS. If the above is difficult, maybe I could have a program that has the if statement run 1 set of
commands on "odd dates" and the other if statement to run on "even dates".

If today is Odd date of month
begin
call A.exe
call B.exe
end

If today is Even date of month
begin
call C.exe
call D.exe
end


Thanks much,


Lawrence M. Seldin, CMC, CPC
Author of POWER TIPS FOR THE APPLE NEWTON and INTRODUCTION TO CSP
Author of RECRUITSOURCE PEOPLESOFT EXAM and RECRUITSOURCE SAP/R3 EXAM


NOTE: To send me an email, remove TAKEOUT from my email address: (e-mail address removed)

NOTE: My web home page: www.seldin.net
 
P

Pegasus \(MVP\)

Lawrence M. Seldin said:
I have Win2k with SP4. In the Scheduler I have a bat script that "calls 4 exe programs". However,
they are taking longer to complete. I don't want to break the script into more than one script.


I have 4 "call exe" statements. I want 2 of them to run on Monday, Wednesday and Friday.
I want the other 2, to run on Tuesday and Thursday.

Something like:

If today is Monday or Wednesday or Friday
begin
call A.exe
call B.exe
end

If today is Tueday or Thursday
begin
call C.exe
call D.exe
end

However, I only want to create a single bat file for both if statements. I already have a Task, in
the task scheduler that runs daily.

PS. If the above is difficult, maybe I could have a program that has the if statement run 1 set of
commands on "odd dates" and the other if statement to run on "even dates".

If today is Odd date of month
begin
call A.exe
call B.exe
end

If today is Even date of month
begin
call C.exe
call D.exe
end


Thanks much,


Lawrence M. Seldin, CMC, CPC
Author of POWER TIPS FOR THE APPLE NEWTON and INTRODUCTION TO CSP
Author of RECRUITSOURCE PEOPLESOFT EXAM and RECRUITSOURCE SAP/R3 EXAM


NOTE: To send me an email, remove TAKEOUT from my email address: (e-mail address removed)

NOTE: My web home page: www.seldin.net

Try this:

@echo off
for /F %%a in ('echo %date%') do goto %%a

:Mon
:Wed
:Fri
call A.exe
call B.exe
goto :eof

:Tue
:Thu
call C.exe
call D.exe
goto :eof

:Sat
:Sun
goto :eof

The above code is based on the environmental variable
%date% returning the day of the week as its first word
in the form Mon, Tue, Wed, Thu, Fri, Sat, Sun.

Note that you do not need the "call" statement
for .exe files.
 
L

Lawrence M. Seldin, CMC, CPC

Pegasus,

Worked great.

Thanks much,




Lawrence M. Seldin, CMC, CPC
Author of POWER TIPS FOR THE APPLE NEWTON and INTRODUCTION TO CSP
Author of RECRUITSOURCE PEOPLESOFT EXAM and RECRUITSOURCE SAP/R3 EXAM


NOTE: To send me an email, remove TAKEOUT from my email address: (e-mail address removed)

NOTE: My web home page: www.seldin.net
 
J

Jerold Schulman

If you want this to work on Windows 2000, Windows XP, Windows Server 2003, future,
use Today.bat from tip 8600 in the 'Tips & Tricks' at http://www.jsiinc.com and day.bat from
tip 7047.


call today MMn DDn YYn Abrev MM DD
call day %YYn% %MM% %DD% daynumb daytext
for /f "Tokens=*" %%a in ('@echo %daynumb%^|findstr "1 3 5"') do goto MWF
for /f "Tokens=*" %%a in ('@echo %daynumb%^|findstr "2 4"') do goto TT
goto :EOF
:MWF
call A.exe
call B.exe
goto :EOF
:TT
call C.exe
call D.exe
endlocal


I have Win2k with SP4. In the Scheduler I have a bat script that "calls 4 exe programs". However,
they are taking longer to complete. I don't want to break the script into more than one script.


I have 4 "call exe" statements. I want 2 of them to run on Monday, Wednesday and Friday.
I want the other 2, to run on Tuesday and Thursday.

Something like:

If today is Monday or Wednesday or Friday
begin
call A.exe
call B.exe
end

If today is Tueday or Thursday
begin
call C.exe
call D.exe
end

However, I only want to create a single bat file for both if statements. I already have a Task, in
the task scheduler that runs daily.

PS. If the above is difficult, maybe I could have a program that has the if statement run 1 set of
commands on "odd dates" and the other if statement to run on "even dates".

If today is Odd date of month
begin
call A.exe
call B.exe
end

If today is Even date of month
begin
call C.exe
call D.exe
end


Thanks much,


Lawrence M. Seldin, CMC, CPC
Author of POWER TIPS FOR THE APPLE NEWTON and INTRODUCTION TO CSP
Author of RECRUITSOURCE PEOPLESOFT EXAM and RECRUITSOURCE SAP/R3 EXAM


NOTE: To send me an email, remove TAKEOUT from my email address: (e-mail address removed)

NOTE: My web home page: www.seldin.net


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
Top