Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I know how to get today's date in Windows 7. here is the command that I am using:

%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

But I want to get yesterday, I do not know how.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
673 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...