JSI Tip 10053. How can I return all 7 days in this week, starting with Sunday, in both short date and long date format?


I have scripted ThisWeek.bat to return all 7 days in this week, starting with Sunday, in both short date and long date format.

The syntax for using ThisWeek.bat is:

for /f "Tokens=1*" %%a in ('ThisWeek') do (
 set sDate=%%a
 set lDate=%%b
 @echo Short Date is:!sDate!    Long Date is:!lDate!
 ...
)

Sample Output

Short Date is:01/08/2006    Long Date is:Sunday, January 08, 2006
Short Date is:01/09/2006    Long Date is:Monday, January 09, 2006
Short Date is:01/10/2006    Long Date is:Tuesday, January 10, 2006
Short Date is:01/11/2006    Long Date is:Wednesday, January 11, 2006
Short Date is:01/12/2006    Long Date is:Thursday, January 12, 2006
Short Date is:01/13/2006    Long Date is:Friday, January 13, 2006
Short Date is:01/14/2006    Long Date is:Saturday, January 14, 2006
ThisWeek.bat contains:
@echo off
setlocal ENABLEDELAYEDEXPANSION
if exist "%TEMP%\ThisWeek.VBS" goto doit
@echo.FirstDay = DateAdd("d", (DatePart("w", Now) * -1)+1, Now) >"%TEMP%\ThisWeek.VBS"
@echo.For i ^= 0 to ^6 >>"%TEMP%\ThisWeek.VBS"
@echo.    WScript.Echo FormatDateTime(DateAdd("d", i, FirstDay), 2) >>"%TEMP%\ThisWeek.VBS"
@echo.Next >>"%TEMP%\ThisWeek.VBS"
@echo.For i ^= 0 to ^6 >>"%TEMP%\ThisWeek.VBS"
@echo.    WScript.Echo FormatDateTime(DateAdd("d", i, FirstDay), 1)  >>"%TEMP%\ThisWeek.VBS"
@echo.Next >>"%TEMP%\ThisWeek.VBS"
:doit
set /a cnt1=0
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\ThisWeek.VBS"') do (
  if !cnt1! GTR 6 (
      set /a cnt2=!cnt1! - 7
      set /a cnt2=!cnt2!*10
      set day=%%a
      call :xtrct set !array! !cnt2!
  ) ELSE (
  call set array=!array!%%a
  )
  set /a cnt1=!cnt1! + 1  
)
endlocal
goto :EOF
:xtrct
call set dt=%%array:~%cnt2%,10%%
@echo %dt% %day%



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