使用批处理bat作为日期系统日期的前三天

在管理server它经常是依据一天来推断载日期系统日志文件,例如,上周五,周一的需要上传日志。上传日志的日期前一天,日志文件命名的日期。这需要获得的日期的前三天。或之前n当天日期。

批量绑定vbs可以实现,如下列文件。

if "%date:~13%"=="一" (set DaysAgo=3) else (set DaysAgo=1)
>"%temp%\MyDate.vbs" echo LastDate=date()-%DaysAgo%
>>"%temp%\MyDate.vbs" echo FmtDate=right(year(LastDate),4) ^& right("0" ^& month(LastDate),2) ^& right("0" ^& day(LastDate),2)
>>"%temp%\MyDate.vbs" echo wscript.echo FmtDate
for /f %%a in ('cscript /nologo "%temp%\MyDate.vbs"') do (set DstDate=%%a)
set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
echo %DstDate%

假设是win8系统能够将if "%date:~13%"改为if "%date:~12%"

set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
设置这个东西的日期格公式

版权声明:本文博主原创文章。博客,未经同意不得转载。

posted @ 2015-10-01 11:57  hrhguanli  阅读(677)  评论(0编辑  收藏  举报