[SOLVED] Extract the named day of the week.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PAB
Posts: 139
Joined: 12 Aug 2019 13:57

[SOLVED] Extract the named day of the week.

#1 Post by PAB » 01 Nov 2019 14:32

Good evening,

I would like to output the day of the week, the date, and the time.

This works exactly as I want for the date and the time . . .

Code: Select all

echo Created: %date% at %time:~0,2%:%time:~3,2%:%time:~6,2%
This does what I want but puts the day number in a two digit format after the named day of the week which is not what I want . . .

Code: Select all

Set daysofweek=Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday  
For /f "Tokens=2-4 Delims=," %%a In ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') Do Set daynumber=%%a
For /f "Tokens=%daynumber% Delims=," %%b In ("%daysofweek%") Do Set day=%%b
echo Created: %day% the %date:~0,3% %date% at %time:~0,2%:%time:~3,2%:%time:~6,2%
For example, for today it should show Friday the 01/11/2019 at whatever time.

Thanks in advance.
Last edited by PAB on 07 Nov 2019 09:36, edited 1 time in total.

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

Re: Extract the named day of the week.

#2 Post by aGerman » 01 Nov 2019 16:09

Code: Select all

@echo off &setlocal
for /f %%i in ('WMIC OS GET LocalDateTime /value ^& WMIC Path Win32_LocalTime GET DayOfWeek /value') do for /f %%j in ("%%i") do set "%%j"
set /a "tok=DayOfWeek+1"
for /f "tokens=%tok%" %%i in ("Sunday Monday Tuesday Wednesday Thursday Friday Saturday") do set "day=%%i"
echo Created: %day% the %LocalDateTime:~6,2%/%LocalDateTime:~4,2%/%LocalDateTime:~0,4% at %LocalDateTime:~8,2%:%LocalDateTime:~10,2%:%LocalDateTime:~12,2%
Probably I reinvented the wheel with this code. No idea how many threads already contain similar snippets.

Steffen

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Extract the named day of the week.

#3 Post by PAB » 01 Nov 2019 16:27

Thank you. Why does it only appear in the cmd window if I put Pause after the last line please?

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

Re: Extract the named day of the week.

#4 Post by aGerman » 01 Nov 2019 17:24

Why does it only appear in the cmd window if I put Pause after the last line please?
It appears anyway. The pause command prevents the script window from closing immediately though.

Steffen

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Extract the named day of the week.

#5 Post by PAB » 01 Nov 2019 18:13

Thank you Steffen, it is appreciated. Have a great weekend!

Post Reply