!BAT time by sratlf 05-18
::usage: %~0 yyyy-mm-dd yyyy-mm-dd
setlocal
debug 0
set t1=%~1
set t2=%~2
::起始日期
set /a y1=%t1:~,4%
set /a m1=%t1:~5,2%
set /a d1=%t1:~-2%
::终止日期
set /a y2=%t2:~,4%
set /a m2=%t2:~5,2%
set /a d2=%t2:~-2%
::值判断
if %m1%<=12 if %m2%<=12 goto :m%m1% || exit
:m1
:m3
:m5
:m7
:m8
:m10
:m12
if %d1%<=31 goto :m_%m2% || exit
:m2
if %d1%<=29 goto :m_%m2% || exit
:m4
:m6
:m9
:m11
if %d1%<=30 goto :m_%m2% || exit
:m_1
:m_3
:m_5
:m_7
:m_8
:m_10
:m_12
if %d2%<=31 goto :start || exit
:m_2
if %d2%<=29 goto :start || exit
:m_4
:m_6
:m_9
:m_11
if %d2%<=30 goto :start || exit
:start
::判断
set time=0
if %y1%>=%y2% || goto :end_time
if %y1%<=%y2% || goto :exchange
if %m1%>=%m2% || goto :end_time
if %m1%<=%m2% || goto :exchange
if %d1%>=%d2% || goto :end_time
if %d1%<=%d2% || goto :exchange
endlocal && set time=0
exit
:exchange
set y1=%y2% && set y2=%y1%
set m1=%m2% && set m2=%m1%
set d1=%d2% && set d2=%d1%
:end_time
if %m2%>=2 set /a time=%time% + 31 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=3 set /a time=%time% + 28 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=4 set /a time=%time% + 31 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=5 set /a time=%time% + 30 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=6 set /a time=%time% + 31 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=7 set /a time=%time% + 30 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=8 set /a time=%time% + 31 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=9 set /a time=%time% + 31 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=10 set /a time=%time% + 30 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=11 set /a time=%time% + 31 || set /a time=%time% + %d2% && goto :end_time_y
if %m2%>=12 set /a time=%time% + 30 || set /a time=%time% + %d2% && goto :end_time_y
set /a time=%time% + %d2%
:end_time_y
calc %y2% - %y1%
calc %@retval% * 365
set /a time=%time% + %@retval%
:start_time
if %m1%>=2 set /a time=%time% - 31 || set /a time=%time% - %d1% && goto :end
if %m1%>=3 set /a time=%time% - 28 || set /a time=%time% - %d1% && goto :end
if %m1%>=4 set /a time=%time% - 31 || set /a time=%time% - %d1% && goto :end
if %m1%>=5 set /a time=%time% - 30 || set /a time=%time% - %d1% && goto :end
if %m1%>=6 set /a time=%time% - 31 || set /a time=%time% - %d1% && goto :end
if %m1%>=7 set /a time=%time% - 30 || set /a time=%time% - %d1% && goto :end
if %m1%>=8 set /a time=%time% - 31 || set /a time=%time% - %d1% && goto :end
if %m1%>=9 set /a time=%time% - 31 || set /a time=%time% - %d1% && goto :end
if %m1%>=10 set /a time=%time% - 30 || set /a time=%time% - %d1% && goto :end
if %m1%>=11 set /a time=%time% - 31 || set /a time=%time% - %d1% && goto :end
if %m1%>=12 set /a time=%time% - 30 || set /a time=%time% - %d1% && goto :end
set /a time=%time% - %d1%
:end
endlocal && set /a time=%time% - 1 > nul
exit
欢迎光临 无忧启动论坛 (http://bbs.wuyou.net/) | Powered by Discuz! X3.3 |