If you're limited to just cmd.exe
, then the other solutions, despite their size, are probably as good as you'll get. However, modern Windows (such as your Win7) ships with quite a few other tools which can do the job far easier.
Just create a VBScript yester.vbs
script as follows:
d = date() - 1
wscript.echo year(d) * 10000 + month(d) * 100 + day(d)
Then you can call it from your cmd
script with:
for /f %%a in ('cscript //nologo yester.vbs') do set yesterday=%%a
and the yesterday
variable will be created in the form yyyymmdd
for you to manipulate however you desire.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…