Check Day in windows 10

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Check Day in windows 10

#1 Post by mohdfraz » 03 May 2018 02:09

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Check Day in windows 10

#2 Post by aGerman » 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

npocmaka_
Posts: 513
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Check Day in windows 10

#3 Post by npocmaka_ » 03 May 2018 05:41


Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: Check Day in windows 10

#4 Post by Squashman » 03 May 2018 06:08

How the date and time variables display is dependent on your regional settings on your computer.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Check Day in windows 10

#5 Post by aGerman » 03 May 2018 06:24

That's true regarding order and separator. I never found a setting of how to enable or disable the leading day of week.

Steffen

SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Re: Check Day in windows 10

#6 Post by SIMMS7400 » 03 May 2018 08:41

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"

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Check Day in windows 10

#7 Post by mohdfraz » 04 May 2018 03:21

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

Post Reply