-3

I need to use date /t command and convert the date format to DD-MM-YYYY weekday like (MON/TUE/WED) with all the "-" and "_" as listed I can't find an answer on my question. Could you please help me?

What I've done so far:

@echo on 
D: 
cd D:\Exe\VBS 
color 0b 
set day=-1 
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2) 
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a" 
del "%temp%\%~n0.vbs" 
set "YYYY=%result:~0,4%" 
set "MM=%result:~4,2%" 
set "DD=%result:~6,2%" 
set "date-yesterday=%yyyy%-%mm%-%dd%" 
echo Yesterday was "%date-yesterday%" 

Required result Fri2019-05-17

LotPings
  • 7,011
  • 1
  • 15
  • 29
Shaf3067
  • 11
  • 3
  • 1
    `date` is not reliable because its output depends on locale. There are already tons of ways on SU: [How can I get the date in a locale independent format in a batch file?](https://superuser.com/q/1287756/241386), [How to get Locale-independent modification date batch](https://superuser.com/q/1396664/241386), [How to get the Date in a batch file in a predictable format?](https://superuser.com/q/315984/241386), [Using Date and Times in a batch file to create a file name](https://superuser.com/q/512163/241386) – phuclv May 17 '19 at 09:07
  • 3
    Possible duplicate of [Batch script (cmd) resulting in DD-MM-YYYY\_weekday format](https://superuser.com/questions/1086136/batch-script-cmd-resulting-in-dd-mm-yyyy-weekday-format) – phuclv May 17 '19 at 09:07
  • DD-MM-YYYY_WEEKDAY ONLY 3 WORDS (LIKE FRI,WED,MON,TUE) – Shaf3067 May 17 '19 at 09:13
  • `DD-MM-YYYY_weekday`, `DD-MM-YYYY weekday` and `Fri2019-05-17` are definitely completely different things – phuclv May 18 '19 at 01:55

1 Answers1

0

Another locale/user settings independent way is to use powershell as a tool.

On cmd line:

@for /f %A in ('powershell -nop -c "get-date -f yyyy-MM-dd_ddd"') do @set "YesterDay=%A"

In a batch file:

@Echo off
for /f %%A in ('
    powershell -nop -c "get-date -f yyyy-MM-dd_ddd"
') do set "YesterDay=%%A"

Your title,text,code and last sentence require different things.

Tweak the -f format string to your liking,
casing is important (lower case mm will be minutes)

LotPings
  • 7,011
  • 1
  • 15
  • 29
  • Thankyou for your response its working ..fine now – Shaf3067 May 21 '19 at 10:10
  • Thanks for feedback. If you find an answer helpful you should consider to [accept the answer](https://superuser.com/help/accepted-answer) and/or [vote up](https://superuser.com/help/why-vote) – LotPings May 21 '19 at 10:13