Solved batch script to return if today is first weekday of month

March 6, 2013 at 08:45:58
Specs: Windows XP
I need a batch script that runs a specific process if the current weekday is the first weekday of the current month, else run a separate batch script if it's anything else. Does anyone have something that does this already?

See More: batch script to return if today is first weekday of month

Report •

#1
March 6, 2013 at 11:51:56
✔ Best Answer
This only works if your date format is like "Sat 03/10/" (year doesn't matter). If not, you might want to use vbscript for date-handling. Batch is fickle about dates.
::===== begin batchscript "weakday"
@echo off & setlocal
rem for testing purposes: set /p dd=date:
set dd=%date%
set z=%dd:~0,1%
set proc=xx.bat
set aa=01
if /i %z% equ s set aa=00
if /i %z% equ m set aa=03
if "%dd:~7,2%" leq "%aa%" set proc=zz.bat
echo calling %proc%
call %proc%
::===== end batch

Report •

#2
March 6, 2013 at 13:37:11
thank you for the post; your help is much appreciated. the if statement z equ s or m is intended to be Sat/Sunday 00 or monday 03, correct? If so, this is exactly what I was looking for. thanks.

Report •

#3
March 6, 2013 at 16:19:35
Yes, monday can be from 1st to 3rd, sat and sun are excluded by zero, and the other weekdays can only be 1st.

Report •

Related Solutions

#4
March 6, 2013 at 23:49:21
This should do you regardless of date layout.

:: =====  script starts here  ===============
:: 
:: 1weekday.bat  2013-03-07 11:06:42.93
@echo off & setLocal enableDELAYedeXpansioN

call :sub1

if !D! lss 4          (
if !day! neq Saturday (
if !day! neq Sunday   (
echo today is !day! the first weekday of the month.
)))

goto :eof

:sub1
@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 DD=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 DD=%%a
set D=%errorlevel%

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

for %%c in (dat day month year) do del %%c.com

goto :eof
::======  script ends here  =================

=====================
M2 Golden-Triangle


Report •

Ask Question