当前位置:DOS资源站资料中心批处理教程 → 批处理日期查询器

批处理日期查询器

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-4-28 21:42:29

注:查询年份从1904年起往后。
---------------------------

@echo off&color 9f&mode con lines=10
title 星期查询器
:set
cls
echo.&echo.&echo.
set var=
set /p var=    请输入要查询的日期(格式为2000年08月08日):
if "%var:~4,1%%var:~7,1%%var:~10,1%"=="年月日" goto year
cls
echo.&echo.&echo.
echo     输入格式不正确!请返回正确输入。&ping /n 3 127.1>nul&goto set
:year
set year=%var:~,4%
set /a str=(%year%-1904)/4&set /a str1=%year%-1904
for /l %%i in (0,1,3) do (
    set a=%%i
    setlocal enabledelayedexpansion
    set /a str2=4*!str!+!a!
    if !str1! equ !str2! goto month
)
:month
endlocal
if %a% equ 0 (set /a number1=%str%*1461) else (set /a number1=%str%*1461+%a%*365+1)
if %var:~5,1% equ 0 (set month=%var:~6,1%) else (set month=%var:~5,2%)
set /a month=%month%-1
if %month% equ 0 set /a number2=0&goto day
if %month% equ 1 set /a number2=31&goto day
if %month% equ 2 set /a number2=31+28
if %month% equ 3 set /a number2=31*2+28
if %month% equ 4 set /a number2=31*2+30+28
if %month% equ 5 set /a number2=31*3+30+28
if %month% equ 6 set /a number2=31*3+30*2+28
if %month% equ 7 set /a number2=31*4+30*2+28
if %month% equ 8 set /a number2=31*5+30*2+28
if %month% equ 9 set /a number2=31*5+30*3+28
if %month% equ 10 set /a number2=31*6+30*3+28
if %month% equ 11 set /a number2=31*6+30*4+28
if %a% equ 0 set /a number2=%number2%+1
:day
if %var:~8,1% equ 0 (set day=%var:~9,1%) else (set day=%var:~8,2%)
set /a number3=%day%-1
:week
set /a number=%number1%+%number2%+%number3%
set /a week=%number%/7
for /l %%i in (0,1,6) do (
    set b=%%i
    setlocal enabledelayedexpansion
    set /a str=!week!*7+!b!
    if !str! equ !number! goto echo
)
:echo