Set Yesterday BATCH FILE

前端 未结 2 956
清酒与你
清酒与你 2021-01-26 11:28

If this gives me today\'s date...

SET TODAY=%date:~7,2%.%date:~-10,2%.%date:~-4,4%

...how can i get yesterday\'s date? Can I get it in the same

2条回答
  •  渐次进展
    2021-01-26 11:56

    Change the order of the three variables in the 3rd last line to suit you:

    :: yesterdays date
    @echo off
    set day=-1
    echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
    echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
    for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
    del "%temp%\%~n0.vbs"
    set "YYYY=%result:~0,4%"
    set "MM=%result:~4,2%"
    set "DD=%result:~6,2%"
    set "date-yesterday=%yyyy%-%mm%-%dd%"
    
    echo Yesterday was "%date-yesterday%"
    pause
    

提交回复
热议问题