Page 1 of 1

Check Day in windows 10

Posted: 03 May 2018 02:09
by mohdfraz
Hi,

I normally use this below code to check "Day" in batch file but in windows 10 it is not working. In older windows date return "Wed 03/05/2018" so it was easy to extra Day from date using below code but in windows 10 it is not working as Windows 10 will return "03/05/2018".
Any suggestion please...
SET D=%date:~0,3%
SET D=%D::=%
if %D% equ Mon (Goto :Mon) Else (Goto :Tue)
Thanks

Re: Check Day in windows 10

Posted: 03 May 2018 05:38
by aGerman
WMIC should be useful

Code: Select all

for /f "tokens=2 delims==" %%i in ('WMIC PATH Win32_LocalTime GET DayOfWeek /value') do for %%j in (%%i) do set "dow=%%j"
Now variable %dow% contains a number in range 0 (for Sunday) until 6 (for Saturday).

Steffen

Re: Check Day in windows 10

Posted: 03 May 2018 05:41
by npocmaka_

Re: Check Day in windows 10

Posted: 03 May 2018 06:08
by Squashman
How the date and time variables display is dependent on your regional settings on your computer.

Re: Check Day in windows 10

Posted: 03 May 2018 06:24
by aGerman
That's true regarding order and separator. I never found a setting of how to enable or disable the leading day of week.

Steffen

Re: Check Day in windows 10

Posted: 03 May 2018 08:41
by SIMMS7400
Try my function - it's region and system agnostic

Code: Select all

:GET_DOW

::-- This parsing method works independently of any regional settings --::
::-- This works from Windows XP to Windows 2012R2 --::
::-- Adjust DOW variable to the required format ^[i.e. Sat or Saturday^]

SET "DOW=Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
SET /A "LINE=0"

FOR /F "tokens=1-9" %%A in ('wmic Path Win32_LocalTime Get Day^,DayOfWeek^,Hour^,Minute^,Month^,Quarter^,Second^,WeekInMonth^,Year ^| FIND /v ""') DO (

  SET /A "LINE += 1"
  IF "!LINE!"=="1" ( SET "VARA=%%A" & SET "VARB=%%B" & SET "VARC=%%C" & SET "VARD=%%D" & SET "VARE=%%E"
					 SET "VARF=%%F" & SET "VARG=%%G" & SET "VARH=%%H" & SET "VARI=%%I")
					 
  IF "!LINE!"=="2" ( SET "!VARA!=%%A" & SET "!VARB!=%%B" & SET "!VARC!=%%C" & SET "!VARD!=%%D" & SET "!VARE!=%%E"
					 SET "!VARF!=%%F" & SET "!VARG!=%%G" & SET "!VARH!=%%H" & SET "!VARI!=%%I")
)

FOR %%A IN (Month Day Hour Minute Second) DO ( IF !%%A! LSS 10 SET %%A=0!%%A!)
SET /A DoWIndex = DayOfWeek + 1
FOR /F "tokens=%DoWIndex%" %%A IN ("%DOW%") DO ENDLOCAL & SET "DOWName=%%A"

Re: Check Day in windows 10

Posted: 04 May 2018 03:21
by mohdfraz
aGerman wrote:
03 May 2018 05:38
WMIC should be useful

Code: Select all

for /f "tokens=2 delims==" %%i in ('WMIC PATH Win32_LocalTime GET DayOfWeek /value') do for %%j in (%%i) do set "dow=%%j"
Now variable %dow% contains a number in range 0 (for Sunday) until 6 (for Saturday).

Steffen
Dear Steffen,
Your solution worked like a charm. Very great full to you. Many Thanks


I thank all others members who replied. Thank you all.

This forum is always good and very actively solve the issues.

Thanks