5 Batch code with Count days 1th/3 page _dos/bat

Source: Internet
Author: User
Tags goto
So I collected the collection after the issue to share with you.
Description
Collecting and finishing: @bbs with the wind. bathome.cn 2008-04-15
First code Author: Would Sort from: Cn-dos
Combined second, code author: Namejm From: Cn-dos
The fifth one is bat combination VBS code, the author and source are unknown.
The first and fifth code, enter a negative number: trace the days after the specified date.
第二、三、四个 code, not tested, but input positive integer is OK. That is to trace the number of days before the specified date.
Code One,
Author: would Sort
Copy Code code as follows:

:: Datedel2.bat-Deletes a file that was modified before the specified number of days under the specified path
:: Author: Would sort-2005-9-2-cmd@winxp from: Cn-dos
:: Note: The variable Tian for the specified number of days, yesterday was 1, the day before the 2, and so on
:: Core algorithm: Ritchie Lawrence, updated 2002-08-13. Version 1.1
::
@echo Off & setlocal enableextensions
Call:D ate2day%date:~0,10% sdays
REM%tian% represents the number of days.
set/p tian= Please specify the number of days to go back:
set/a Sdays-=tian
Call:D ay2date%sdays% difdate
Echo.&echo.
The date specified by ECHO is:%date:~0,10%
Echo.
echo%tian% days ago is:%difdate%
Echo.&pause
Exit
:D Ate2day
Setlocal enableextensions
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
:D ay2date
Setlocal enableextensions
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 set mm=0%mm%) & (if%dd% LSS set dd=0%dd%)
Endlocal&set%2=%yy%-%mm%-%dd%&goto:eof

Code two,
The following three code authors are all NAMEJM
Copy Code code as follows:

:: Author: Namejm honorary moderator from: Cn-dos
@echo off
:: Find the date before n days
:: Ideas:
:: Simulation manual operation, with the date number minus the number of days, the difference is negative to high to borrow 1.
:: Features:
:: Code concise, easy to understand, speed depends on the size of the specified number of days
:: Date can be brought week, however, must be in the order of year and month
:: The year must be four digits, or there will be an error
@echo off
: Main
Cls
Set day=%date%
Set Days=0
Echo.&echo.
The date specified by ECHO is:%day%
Echo.
set/p input= Please specify the number of days to go back:
Setlocal enabledelayedexpansion
:: Date Extracted
for/f "Tokens=1-3 delims=-/."%%i in ("%day%") Do (
set/a sy=%%i, sm=100%%j%, sd=100%%k% 100
)
set/a Sd-=input
If%sd% Leq 0 call:count
Cls
Echo.&echo.
The date specified by ECHO is:%day%
Echo.
Set sm=0%sm%
Set sd=0%sd%
echo%input% days ago is:%sy%-%sm:~-2%-%sd:~-2%
Pause>nul
Goto Main
: Count
set/a sm-=1
If!sm! Equ 0 set/a sm=12, sy-=1
Call:d ays
set/a sd+=days
If%sd% leq 0 goto Count
Goto:eof
:d ays
:: Gets the total number of days for a 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


Current 1/3 page 123 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.