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

后端 未结 2 1302
鱼传尺愫
鱼传尺愫 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.

提交回复
热议问题