I'm trying to zero pad the month in a Windows 7 batch file that uses the date, specifically the month. I haven't been able to work out joining "0" to 7 successfully. Any ideas?
ECHO off
SETLOCAL
FOR /f %%I in ('wmic os get localdatetime /FORMAT:list ^| FIND "="') do SET "%%I"
SET "YYYY=%localdatetime:~0,4%"
SET /a "MM=1%localdatetime:~4,2% - 100"
SET "DD=%localdatetime:~6,2%"
FOR /f "tokens=%MM%" %%I in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do SET "month=%%I"
IF %MM% LSS 10 (ECHO %MM%
:: SET "%MM%=0%MM%" no dice
SET %MM%=%MM%
ECHO %MM%)
:: KLUDGE FOR TIMES UP TILL OCTOBER!
:: SET USdate=%YYYY%0%MM%%DD%
SET USdate=%YYYY%%MM%%DD%
:: US FORMAT 20180720
ECHO %USdate%
I can kludge the string, but come October, it won't work :) I've included the date, which I got from here