How to get 3 days past date from current date Using Batch file

后端 未结 2 1299
鱼传尺愫
鱼传尺愫 2020-12-07 05:55

I am Using \"%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%\" to get current date using batch file

Now how can I get the date of 3 days past from today using Batch

相关标签:
2条回答
  • 2020-12-07 06:18

    One more way using jscript embedded into cmd script. Here's the dayAdder.bat that accepts only one argument - the days you want to add to the current date and prints the result:

      @if (@X) == (@Y) @end /* JScript comment 
        @echo off   
        cscript //E:JScript //nologo "%~f0" %*
        exit /b %errorlevel%       
    @if (@X)==(@Y) @end JScript comment */
    
    var days=parseInt(WScript.Arguments.Item(0));
    
    
    Date.prototype.addDays = function(days) {
        var date = new Date(this.valueOf());
        date.setDate(date.getDate() + days);
        return date;
    }
    
    var date = new Date();
    
    WScript.Echo(date.addDays(5));
    WScript.Echo("Year: " + date.getFullYear());
    WScript.Echo("Month: " + date.getMonth());
    WScript.Echo("DayOfTeWEek: " + date.getDay());
    

    examaple:

    E:\scripts>dayAdder.bat 7
    Sun Nov 8 16:27:48 UTC+0200 2020
    Year: 2020
    Month: 10
    DayOfTeWEek: 2
    DayOfTheMonth: 3
    

    You can modify it in way that will be suitable for you.

    0 讨论(0)
  • 2020-12-07 06:25

    This will give you a robust date 3 days into the future.

    @echo off
    set day=3
    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 "d=%yyyy%-%mm%-%dd%"
    
    echo %d%"
    pause
    
    0 讨论(0)
提交回复
热议问题