如何在批处理文件中获取昨天的日期 [英] how to get yesterday's date in a batch file

查看:49
本文介绍了如何在批处理文件中获取昨天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在 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.

推荐答案

如果您仅限于只是 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 yester.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

yesterday 变量将以 yyyymmdd 的形式创建,供您随意操作.

and the yesterday variable will be created in the form yyyymmdd for you to manipulate however you desire.

这篇关于如何在批处理文件中获取昨天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆