L
L
lik1732021-06-10 12:37:17
cmd/bat
lik173, 2021-06-10 12:37:17

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%


Also supplemented by this:
if %acday%==%today% (
if %month%==%tomonth% set "hb=echo Happy birthday!" && goto next
) else (goto next)

in this very :next code like this (initially put set "hb=rem aaa"):
cls
%hb%
echo Hello, %name%!
echo Today: %today%.%tomonth%.%toyear%


When executed, it outputs:
Hello, lik173!
Today: 10.Month=2.2021


Why Month=2? Now 6 months.

Conclusion 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

And hour 9 shows
A so 12 hours

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2021-06-10
@lik173

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

E
Eugene, 2021-06-10
@yellowmew

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:listand 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 question

Ask a Question

731 491 924 answers to any question