Batch code for 5 calculation days page 1 / 3


So I sent out my collection for you to share.
    Collection and arrangement:   With the wind  @     2008-04-15
    The first code   Author: will   Sort    From: CN DOS
    The second, third, fourth and third codes   Author: namejm   From: CN DOS
    The fifth is   bat   combination   vbs   The code, author and source are unknown.
For the first and fifth codes, the negative number is the number of days after the specified date.
The second, third and fourth codes are not tested, but it is OK to enter positive integers. That is, the number of days before the specified date.
Code 1
       Author: will   Sort

Copy codeThe code is as follows:
::   DateDel2.bat  –  Delete the file modified before the specified number of days in the specified path
::   Author: will   Sort  –  2005-9-2  –  [email protected]   From: CN DOS
::   Note: Variables   tian   For the specified number of days, yesterday is 1, the day before yesterday is 2, and so on
::   Core algorithm: Ritchie   Lawrence,   updated   2002-08-13.   Version   one point one
@echo off & setlocal ENABLEEXTENSIONS 
call :Date2Day %date:~0,10% sdays
rem   The downward% Tian% represents the number of days
set  / p   tian=        Please specify the number of days to trace:
set /a sdays-=tian
call :Day2Date %sdays% difdate
echo         The date specified is:   % date:~0,10%
echo        % tian%   The date before is% difdate%
for /f “tokens=1-3 delims=/-, ” %%a in (‘echo/%1’) do ( 
  set yy=%%a & set mm=%%b & set dd=%%c 
set /a dd=100%dd%%%100,mm=100%mm%%%100 
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %2=%j%&goto :EOF 
set /a i=%1,a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a 
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) 
endlocal&set %2=%yy%-%mm%-%dd%&goto :EOF

Code 2
    The following three code authors are all   namejm

Copy codeThe code is as follows:
::   Author:   namejm     Honorary moderator   From: CN DOS
@echo off
::   Find the date n days ago
::   Thinking:
::   Simulate manual operation, subtract the number of days from the number of days, and borrow 1 from the high position when the difference is negative.
::   characteristic:
::   Code concise, easy to understand, speed depends on the size of the specified number of days
::   Dates can take weeks, but they must be arranged in chronological order
::   The year must be four digits, otherwise there will be an error
@echo off
set day=%date%
set days=0
echo         The specified date is% day%
set  / p   input=        Please specify the number of days to trace:
setlocal enabledelayedexpansion
::   Date of withdrawal
for /f “tokens=1-3 delims=-/. ” %%i in (“%day%”) do (
    set /a sy=%%i, sm=100%%j %% 100, sd=100%%k %% 100
set /a sd-=input
if %sd% leq 0 call :count
echo         The specified date is% day%
set sm=0%sm%
set sd=0%sd%
echo        % input%   The previous date is% sy% -% SM: ~ – 2% -% SD: ~ – 2%
goto Main
set /a sm-=1
if !sm! equ 0 set /a sm=12, sy-=1
call :days
set /a sd+=days
if %sd% leq 0 goto count
goto :eof
::   Gets the total number of days in the specified month
set /a leap=”^!(sy %% 4) & ^!(^!(sy %% 100)) | ^!(sy %% 400)”
set /a max=28+leap
set num=0
set str=31 %max% 31 30 31 30 31 31 30 31 30 31
for %%i in (%str%) do (
    set /a num+=1
    if %sm% equ !num! set days=%%i&goto :eof
goto :eof

123 read the full text on the next page