Another way to convert a date to the day number and day name.

I first scripted Day.bat to convert a date to the day number and day name.

Using the VBScript weekday function, I have scripted DayWeek.bat to convert a date to the day number and day name.

The syntax for using DayWeek.bat is:

\[call\] DayWeek Dt DayNumb DayText

Where:

Dt      is a date, using your shortdate format, like 09/28/2006.

DayNumb is a call directed numeric environment variable that will contain the day number,
        per the following: 0 Unknown
                           1 Sunday
                           2 Monday
                           3 Tuesday
                           4 Wednesday
                           5 Thursday
                           6 Friday
                           7 Saturday

DayText is a call directed environment variable that will contain the day text.
DayWeek.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax: DayWeek Dt DayNumb DayText&goto :EOF
setlocal
if exist "%TEMP%\DayWeek.vbs" goto :doit
@echo.Dim Arguments >"%TEMP%\DayWeek.vbs"
@echo.Set Arguments = Wscript.Arguments >>"%TEMP%\DayWeek.vbs"
@echo.wScript.Echo weekday(Arguments(0)) >>"%TEMP%\DayWeek.vbs"
:doit
set /a DayNumb=0
for /f "Tokens=1" %%a in ('cscript //nologo "%TEMP%\DayWeek.vbs" %1') do (
 set /a DayNumb=%%a
)
If %DayNumb% EQU 0 set DayText=Unknown&goto :finish
set daytab=Sunday###Monday###Tuesday##WednesdayThursday#Friday###Saturday#
set /a Day=%DayNumb% -1
set /a Day=%Day% * 9
call set DayText=%%daytab:~%day%^,9%%
set DayText=%DayText:#=%
:finish
endlocal&set /a %2=%DayNumb%&set %3=%DayText%


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish