@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONFOR /F "tokens=1-6 delims= " %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO ( ECHO NOW IS: "%%A" "%%B" "%%C" "%%D" "%%E" "%%F" SET Day=%%A SET Hour=%%B SET Min=%%C SET Month=%%D SET Sec=%%E SET Year=%%F)ECHO Day=%day%ECHO Hour=%Hour%ECHO Min=%Min%ECHO Month=%Month%ECHO Sec=%Sec%ECHO Year=%Year%PAUSE
I whant to use WMIC because date format may dramatically change.
I resolved it.
Here is my working code.
Thanks for your help,
Rene
@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONFOR /F "skip=1 tokens=1-6 delims= " %%A IN ('WMIC ^Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO ( ECHO NOW IS: "%%A" "%%B" "%%C" "%%D" "%%E" "%%F" IF %%A GTR 0 ( SET Day=%%A SET Hour=%%B SET Min=%%C SET Month=%%D SET Sec=%%E SET Year=%%F ))ECHO Day=%day%ECHO Hour=%Hour%ECHO Min=%Min%ECHO Month=%Month%ECHO Sec=%Sec%ECHO Year=%Year%PAUSE
Just tried "date /t" and it's format did change depending of the Environment date format setting
Bill Prew
I know this is closed, I Was working today, what can I say.
Here's how I do it with WMIC when I want to go that route. Nearly the same but wanted to share my approach when I need leading zeros pn the day and month fields since WMIC doesn't do that.
In addition, I also often use this very useful utility to get todays date into variables, or a date offset from today by a certain amount.
REM First get the pieces of todays date in various formats neededfor /f "skip=2 tokens=2-4 delims=," %%A in ('WMIC Path Win32_LocalTime Get Day^,Month^,Year /Format:csv') do ( REM values without leading zeros set "d=%%A" set "m=%%B" set "yyyy=%%C")REM Build corresponding values with leading zerosset "mm=%m%"set "dd=%d%"if %m% LSS 10 set "mm=0%m%"if %d% LSS 10 set "dd=0%d%"
May I ask you something, I am not very sure why does is it that it is able to set WMIC output to variable after you have add the if %%A is greater than 0 condition.
I whant to use WMIC because date format may dramatically change.
I resolved it.
Here is my working code.
Thanks for your help,
Rene
Open in new window