我当前的代码在今天的修改日期工作正常,但是现在我希望我的代码能够复制第1天的数据以及今天的数据。
@ECHO OFF
FOR /F "tokens=2 delims= " %%V IN ("%DATE%") DO SET TDY=%%V
xcopy /y "DATA_PATH" "LOCAL_SYSTEM" /d:%TDY%
SET TDY=
答案 0 :(得分:1)
使用BAT / VBS解决方案获取昨天日期的方法:
<强> Yesterday.bat 强>
@echo off
>yesterday.vbs echo wscript.echo DateAdd("d", -1, Date(^)^)
for /f "delims=" %%a in ('cscript /nologo yesterday.vbs') do set "$yesterday=%%a"
Echo Yesterday'Date is ==^> %$Yesterday%
如果您希望直接将/
字符替换为-
,例如:
<强> Yesterday.bat 强>
@echo off
>yesterday.vbs echo wscript.echo replace((DateAdd("d", -1, Date(^)^)^),"/","-"^)
for /f "delims=" %%a in ('cscript /nologo yesterday.vbs') do set "$yesterday=%%a"
Echo Yesterday'Date is ==^> %$Yesterday%
答案 1 :(得分:0)
您需要下载datex.exe:
For /f %%a in ('DateX -o -1 -f yyyymmdd') do Set "PreDate=%%a"
datex用法:
4:12:56.76 c:\>datex /?
DateX 2.7 - (C) 2004-2010 by Bill Stewart (bstewart@iname.com)
Usage: datex [-d date] [-f format] [-i num] [-o offset] [-t]
-d Specifies a date.
-f Specifies the format for the date.
-i Output the date represented by the specified number (inverse of -t).
-o Specify a number-of-days difference.
-t Output the date as a number for comparison purposes.
Without arguments, DateX prints the current date and time.