我知道如何在Windows 7中获取今天的日期.这是我正在使用的命令:
%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
Run Code Online (Sandbox Code Playgroud)
但我想昨天得到,我不知道怎么做.
我希望从7天前开始在Windows批处理文件中设置日期.我想以下面的格式这样做.
set today=%date:~10,4%-%date:~4,2%-%date:~-7,2%
Run Code Online (Sandbox Code Playgroud)
任何想法如何在这里减去7天的时间增量?
我一直在绞尽脑汁试图弄清楚这一点。
这段代码
@echo off
powershell $Yesterday = (get-date((get-date).addDays(-1)) -format yyyyMMdd)
echo %Yesterday%
::neither one of these echo anything
@echo off
powershell Set-Variable -Name "Yesterday" -Value (get-date((get-date).addDays(-1)) -format yyyyMMdd)
echo %Yesterday%
Run Code Online (Sandbox Code Playgroud)
都应该返回昨天日期的响应(格式为 yyyMMdd),但是,它们没有。使用 powershell,以下代码确实有效并返回正确的响应:
$Yesterday = (get-date((get-date).addDays(-1)) -format yyyyMMdd)
Write-Host $Yesterday
::Both of these work in powershell
Set-Variable -Name "Yesterday" -Value (get-date((get-date).addDays(-1)) -format yyyyMMdd)
Write-Host $Yesterday
Run Code Online (Sandbox Code Playgroud)
但批量使用时不起作用。有什么想法吗?我试图设置该变量%Yesterday%以便稍后在脚本中使用它,但它的行为并不像我预期的那样。我确信它很简单,但我现在还不知道它是什么。