Answer the question
In order to leave comments, you need to log in
Why is bat outputting the wrong month to wmic?
Worth the script:
for /f %%j in ('wmic path win32_utctime get /format:list ^| findstr "Day="') do (
set "toda=%%~j"
)
for /f %%t in ('wmic path win32_utctime get /format:list ^| findstr "Month="') do (
set "tomont=%%~t"
)
for /f %%i in ('wmic path win32_utctime get /format:list ^| findstr "Year="') do (
set "toyea=%%~i"
)
set today=%toda:~4,5%
set tomonth=%tomont:~6,7%
set toyear=%toyea:~5,8%
if %acday%==%today% (
if %month%==%tomonth% set "hb=echo Happy birthday!" && goto next
) else (goto next)
cls
%hb%
echo Hello, %name%!
echo Today: %today%.%tomonth%.%toyear%
Hello, lik173!
Today: 10.Month=2.2021
wmic path win32_utctime get /format:list
:Day=10
DayOfWeek=4
Hour=9
Milliseconds=
Minute=35
Month=6
Quarter=2
Second=18
WeekInMonth=2
Year=2021
Answer the question
In order to leave comments, you need to log in
Because the value from the last record filtered by findstr was assigned: WeekInMonth=2
You can filter the columns that it will return in the wmic call:
As for the hours - it's all just you call win32_utctime - it returns the time in UTC, oddly enough. Obviously, the Moscow time zone is set in Windows - +3 to UTC.
Use win32_localtime instead of win32_utctime.
wmic path win32_utctime get Month /format:list
win32_ utc time
see what time it is in UTC and you (as far as I understand you live in Moscow time
, also, for debugging - display the result for yourself
wmic path win32_utctime get /format:list
and look carefully.
Now is the second week of the month and this line is the last one (and not the month itself) - that's why your filters pick it
out.In general, bury the stewardess already and write in powershell, unless, of course, you are engaged in archeology.Note: use Windows Powershell and not the latest available Posh 7.Working with wmi is only in windows powershell, from newer ones versions, it was cut out for the sake of cross-platform
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question