0

I want to display the name of the day from a given date. I have a code that can give me the name's day from the system's date.

@for /F "tokens=1 delims=, " %%i In ('powershell date') do set dow=%%i
echo %dow%

How can I be able to display the day's name of any date that I will put in? I want to do something like this (I have already set the variables day, month and year before):

@for /F "tokens=1 delims=, " %%i In ('powershell %day%/%month%/%year%') do set dow=%%i
echo %dow%
LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46
R.Omar
  • 141
  • 1
  • 2
  • 11

1 Answers1

0

Adapted from https://technet.microsoft.com/en-us/library/ff730960.aspx:

for /f "delims=" %%d in ('powershell (get-date  %day%/%month%/%year%^).dayofweek') do set dow=%%d

For testing purposes:

@echo off
:...
echo Command line: powershell (get-date  %day%/%month%/%year%).dayofweek
echo Result:
powershell (get-date  %day%/%month%/%year%).dayofweek
for /f "delims=" %%d in ('powershell (get-date  %day%/%month%/%year%^).dayofweek') do set dow=%%d
echo dow=%dow%
LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46
  • @LS_DEV when i try the code : `@echo off` `for /f "delims=" %%d in ('powershell (get-date %day%/%month%/%year%^).dayofweek') do set dow=%%d` `echo %dow%` it gives me on the command prompt : `ECHO is off` . Should I have some options enabled on my cmd before running the program? (Knowing it worked well when I tried it yesterday) – R.Omar Oct 11 '17 at 08:26
  • Did you define `year`, `month` and `day` before call? – LS_ᴅᴇᴠ Oct 11 '17 at 08:29
  • Test output using `powershell (get-date %day%/%month%/%year%).dayofweek` – LS_ᴅᴇᴠ Oct 11 '17 at 08:31
  • yes i have them already defined before calling them. How can I test `powershell (get-date %day%/%month%/%year%).dayofweek` ? (I'm a beginner in cmd.exe) . When i test `echo powershell (get-date %day%/%month%/%year%).dayofweek` it gives me `powershell (get-date 31/10 /2017).dayofweek` – R.Omar Oct 11 '17 at 08:41
  • Just place `powershell ...` before `for ...`in batch, so you will see result from ps call which must be the same as for will catch. – LS_ᴅᴇᴠ Oct 11 '17 at 08:51
  • ok, i found where the problem come from, it's because when i define my date the output contain spaces. `set thedateis=20/10/2017` `for /F "tokens=1,2,3 delims=/" %%a in ('echo %thedateis%') do set day=%%a & set month=%%b & set year=%%c` `echo The chosen date is: %thedateis%, Day:.%day%., Month:.%month%., Year:.%year%.` it gives me `The chosen date is: 20/10/2017, Day:.20 ., Month:.10 ., Year:.2017.` but i don't know how to get rid of the spaces – R.Omar Oct 11 '17 at 09:10
  • use `DO (` new line `SET day=%%a`, new line ... `)` – LS_ᴅᴇᴠ Oct 11 '17 at 09:25
  • You were doing well, with a new question... – LS_ᴅᴇᴠ Oct 11 '17 at 09:28
  • It worked very well, thanks for your help. – R.Omar Oct 11 '17 at 09:39