Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 21876
  • Last Modified:

get day of week in dos batch file???

Users on my network have a logon script called LOGON.BAT

I want to perform specific processing based upon day of the week.  Basically if the day of the week is Tuesday, Thursday, Saturday, or Sunday I want some specific processing to take place.  If not, just exist.

How can I code my LOGON.BAT file to check for those specific days????
0
NEARNG
Asked:
NEARNG
  • 3
1 Solution
 
brianadkinsCommented:
for /f %%a in ('date /t') do set DAY=%%a

then just check for specific values, I.e.:

if %DAY%=Fri goto :skipprocessing
0
 
brianadkinsCommented:
forgot the double equal sign as a comparator:

----------------8<-------------------------------
for /f %%a in ('date /t') do set DAY=%%a

if %DAY%==Mon goto :skipprocessing
if %DAY%==Wed goto :skipprocessing
if %DAY%==Fri goto :skipprocessing

:: put your processing here

:skipprocessing
----------------8<-------------------------------
0
 
NEARNGAuthor Commented:
That worked!!!!  Thanks Brian!

Can I ask you one more question related to this??  I have increased the point value for your efforts.

Desktops on my network all have characters 12 and 13, of their computer name, as WK.

Laptops have an NB for characters 12 and 13.  So, my laptop is ABAB-98989-NBL1.  

What I want is for all laptops to perform the processing no matter what day it is.  This is because laptops "touch" the network at infrequent times.  So, if characters 12 and 13 of the computer name equal to NB...  Perform processing every day.

Desktops can "skipprocessing" on Mon, Wed, and Fri.

Can you help??

Thanks!!!!!!!

Eric
0
 
brianadkinsCommented:

Something like this should work...  If the 2 chars starting with char 11 are 'NB', just skip ahead and start the processing...

(the character positions begin with zero, so 11,2 should be chars 12 and 13)

the '/i' in the IF command means case insensitive

----------------8<-------------------------------

if /i "%computername:~11,2%"=="NB" goto :process

for /f %%a in ('date /t') do set DAY=%%a
if %DAY%==Mon goto :skipprocessing
if %DAY%==Wed goto :skipprocessing
if %DAY%==Fri goto :skipprocessing

:process
:: put your processing here

:skipprocessing
----------------8<-------------------------------

-Brian
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now