Link to home
Start Free TrialLog in
Avatar of ammounpierre
ammounpierre

asked on

Getting Day of Week from DOS ?

Hello Gurus,
I am running a script to backup files using robocopy.
my batch file uses date /t to get the 3 letters for the date.
now my problem is that depending on the settings in the regional settings in the control panel...
date /t does not give me Fri for example but rather 29 or 05 ....
and I do not want to change the settings... (there are many laptops to backup and each has a separate settings...)
So is there a way to get the 3 letters for the DOW from dos ?
thanks.
Avatar of Qlemo
Qlemo
Flag of Germany image

This little script will give you the 3 letters day of week independant of regional settings (but the name is different for each country, of course) in var DOW.
@echo off
> dow.vbs echo wscript.echo left^(weekdayname^(weekday^(now^)^),3^)
for /F %%D in ('cscript dow.vbs') do set dow=%%D
del dow.vbs >nul

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AbqBill
AbqBill
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this.  Put in a batch file and run it at the command line.

Then try at the command line

set dow

and see what it reports back.  I think it might be universal in operation.  It is code I picked up from the 'Net when having to do some date stuff.


echo. | date | FIND "(mm" > NUL
 
IF errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
GOTO :EOF
 
:Parsedate
FOR /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
   set %1=%%A&set %2=%%B&set YYYY=%%C
   ) else (
set DOW=%%A&set %1=%%B&set %2=%%C&set YYYY=%%D)
 
Set DateStamp=%YYYY%%MM%%DD%
echo DateStamp: %DateStamp%  ( day of the week: %DOW% )
echo.

Open in new window

dbrunton,
this does not work for the DOW, as it is not always contained in date output. If the DOW is in date /t, it is trivial, else comes the difficult part.
As Qlemo pointed out, date information manipulation using plain shell-scripting code is often not trivial, particularly with different locales that use different output formats for the built-in commands. That's why I wrote the datex utility -- I have found it greatly simplifies shell script code when this kind of functionality is needed. Bill.