Be seen. Boost your questionâ€™s priority for more expert views and faster solutions
@echo off
setlocal enabledelayedexpansion
set /a Line=0
for /f "tokens=1-9" %%a in ('wmic Path Win32_LocalTime Get Day^,DayOfWeek^,Hour^,Minute^,Month^,Quarter^,Second^,WeekInMonth^,Year ^| find /v ""') do (
set /a Line += 1
if "!Line!"=="1" (set VarA=%%a&set VarB=%%b&set VarC=%%c&set VarD=%%d&set VarE=%%e&set VarF=%%f&set VarG=%%g&set VarH=%%h&set VarI=%%i)
if "!Line!"=="2" (set !VarA!=%%a&set !VarB!=%%b&set !VarC!=%%c&set !VarD!=%%d&set !VarE!=%%e&set !VarF!=%%f&set !VarG!=%%g&set !VarH!=%%h&set !VarI!=%%i)
)
set /a i = 1&for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do (set Month[!i!]=%%a&set /a i+=1)
set /a Leap = Year %% 4&if !Leap!==0 (set Month[2]=29)
set /a pYear = Year
set /a pMonth = Month
set /a pDay = Day - 1
if !pDay!==0 (
set /a pMonth -= 1
if !pMonth!==0 (
set /a pYear -= 1
set /a pMonth = 12
)
)
if !pDay!==0 (set pDay=!Month[%pMonth%]!)
for %%a in (Month Day Hour Minute Second pMonth pDay) do (if !%%a! LSS 10 set %%a=0!%%a!)
REM *** At this point, the variables Day, DayOfWeek, Hour, Minute, Month, Quarter, Second, WeekInMonth, and Year are set.
REM *** Month, Day, Hour, Minute, Second have leading zeroes if less than 10.
REM *** In addition, the following variables for the previous day are set: pDay, pMonth, pYear
echo Previous day: %pMonth%/%pDay%/%pYear%
Open in new window