如何在一个批处理文件中获取昨天的日期 [英] how to get yesterday's date in a batch file
问题描述
我知道如何在Windows 7中获得今天的日期。这里是我使用的命令:
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.
推荐答案
如果你只限于 em> cmd.exe
,那么其他的解决方案,尽管他们的大小,可能会很好,你会得到。然而,现代Windows(如Win7)附带了相当多的其他工具,可以使工作更容易。
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.
只需创建一个VBScript yesterday.vbs
脚本如下:
Just create a VBScript yester.vbs
script as follows:
d = date() - 1
wscript.echo year(d) * 10000 + month(d) * 100 + day(d)
然后,您可以从 cmd
脚本中调用它:
Then you can call it from your cmd
script with:
for /f %%a in ('cscript //nologo yester.vbs') do set yesterday=%%a
和昨天
变量将以 yyyymmdd
的形式创建,以便您操作你愿意。
and the yesterday
variable will be created in the form yyyymmdd
for you to manipulate however you desire.
这篇关于如何在一个批处理文件中获取昨天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!