|
anqing
高级用户
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
『第
16 楼』:
Quote: | Originally posted by zh159 at 2007-2-9 06:05:
借楼上的:
MsgBox WeekdayName(Weekday(CDate(Now)-18))
+-天数
[code]@echo off
:loop
cls
echo.
set input=
set week=+0
set /p input= 请输入日期(格式: 200 ... |
|
上面的delims=-这句应该用不上的
|
|
2007-2-9 07:16 |
|
|
zh159
金牌会员
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第
17 楼』:
Quote: | Originally posted by anqing at 2007-2-8 18:16:
上面的delims=-这句应该用不上的 |
|
没错,而且"tokens=* delims=-"都可以不用
|
|
2007-2-9 07:43 |
|
|
26933062
银牌会员
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第
18 楼』:
这是我作的通过日期计算天数的批处理,太臃肿了,请高手简化一下,谢谢
@echo off
::通过日期计算天数
set kai=0
set wan=0
set dangq=%date:~0,4%
set /p n=请输入要查询的日期 格式(19950110) :
set nian=%n:~0,4%
set lsyue=%n:~4,2%&set lsri=%n:~6,2%
if %n:~4,1% equ 0 set lsyue=%n:~5,1%
if %n:~6,1% equ 0 set lsri=%n:~7,1%
set dqyue=%date:~5,2%&set dqri=%date:~8,2%
if %date:~5,1% equ 0 set dqyue=%date:~6,1%
if %date:~8,1% equ 0 set dqri=%date:~9,1%
::得到有几个 er 润年
set er=0
set /a xt=%dangq%/4
set /a xt2=%xt%*4
if %xt2% equ %dangq% (
if %dqyue% gtr 2 set /a er+=1
)
if %nian% equ %dangq% (
if %n:~4,2% equ %date:~5,2% set /a kai=%dqri%-%lsri%&goto ok
goto tian
)
:1
set /a sr=%nian%/4
set /a yan=%sr%*4
if %yan% equ %nian% set /a er+=1
set /a nian=%nian%+1
if %nian% equ %dangq% goto tian
goto 1
:tian
if %dqyue% equ 1 set kai=%dqri%&goto lis
set kai=31
if %dqyue% equ 2 set /a kai=%kai%+%dqri%&goto lis
set /a kai=%kai%+28
set yue=3
set syue=4
:2
if %dqyue% equ %yue% set /a kai=%kai%+%dqri%&goto lis
set /a kai=%kai%+31
if %dqyue% equ %syue% set /a kai=%kai%+%dqri%&goto lis
set /a kai=%kai%+30
set /a yue+=2&set /a syue+=2&goto 2
:lis
if %n:~0,4% equ %dangq% set /a kai=%kai%-%lsri%&goto ok
if %lsyue% equ 1 set /a wan=31-%lsri%+334&goto jian
if %lsyue% equ 2 set /a wan=28-%lsri%+306&goto jian
set lyue=3
set lsyuee=4
set var=5
set num=4
:3
if %lsyue% equ %lyue% set /a wan=31-%lsri%+%var%*31+%num%*30&goto jian
set /a num-=1
if %lsyue% equ %lsyuee% set /a wan=30-%lsri%+%var%*31+%num%*30&goto jian
set /a var-=1
set /a lyue+=2&set /a lsyuee+=2&goto 3
:jian
set niane=%n:~0,4%
:4
set /a niane+=1
if %niane% equ %dangq% goto ok
set /a wan=%wan%+365&goto 4
:ok
set /a ts=%kai%+%er%
set /a ts=%ts%+%wan%
echo %n:~0,4%-%n:~4,2%-%n:~6,2% 距今天相差 %ts% 天
echo.
echo 其中有 %er% 个润年
pause>nul
[ Last edited by 26933062 on 2007-2-9 at 01:39 AM ]
|
|
2007-2-9 14:38 |
|
|
zh159
金牌会员
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第
19 楼』:
这两天玩的
@echo off
:loop
cls
echo.
set toDate=
set /p toDate= 请输入日期(格式: 20070101):
if not defined toDate exit
echo.
>tmp.vbs echo wscript.echo datediff("d",#%date:~0,10%#,#%toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2%#)
for /f %%i in ('"cscript //nologo tmp.vbs"') do call echo %toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2% 距今天相差 %%i 天
del tmp.vbs
echo.
pause
goto loop [ Last edited by zh159 on 2007-2-9 at 02:00 AM ]
|
|
2007-2-9 14:59 |
|
|
26933062
银牌会员
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第
20 楼』:
谢谢大家的答案
总结综合了大家的方法,终于搞出来了,请大家帮忙看一看,改一改
::通过日期计算天数并显示星期
::通过天数计算日期并显示星期
@echo off
:loop
set xuanz=
cls&echo.&echo 按 t 使用天数查询, 按 r 或任意键使用日期查询.
echo.&set /p xuanz= 请选择: [t,r]:
if "%xuanz%"=="t" goto tgtian
cls&echo.&echo 当前日期是 %date%&echo.&set toDate=
echo 请输入要查询的日期 格式 (20070101)
echo.&echo 若要查询 “当前日期以后” 的日期 请先输入 + 号 如: (+20080102)
echo.&set /p toDate= 请输入:
if not defined toDate exit
if %toDate:~0,1%==+ (
if %toDate:~1,4%-%toDate:~5,2%-%toDate:~7,2% leq %date:~0,10% (
cls&echo.&echo 您输入的是 %toDate% 若要查询当前日期以前的日期,请不要输入 + 号
echo.&echo 您的输入有误,请按任意键重新输入.........
pause>nul&goto loop
)
)
if not %toDate:~0,1%==+ (
if %toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2% geq %date:~0,10% (
cls&echo.&echo 您输入的是 %toDate% 若要查询当前日期以后的日期,请先输入 + 号
echo.&echo 您的输入有误,请按任意键重新输入.........
pause>nul&goto loop
)
)
if "%toDate:~0,1%"=="+" goto yihou
>tmp.vbs echo wscript.echo datediff("d",#%date:~0,10%#,#%toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2%#)
goto yiqian
:yihou
>tmp.vbs echo wscript.echo datediff("d",#%toDate:~1,4%-%toDate:~5,2%-%toDate:~7,2%#,#%date:~0,10%#)
for /f %%i in ('"cscript //nologo tmp.vbs"') do call set ook=%toDate:~1,4%-%toDate:~5,2%-%toDate:~7,2% 距今天相差 %%i 天&set week=%%i
goto del_
:yiqian
for /f %%i in ('"cscript //nologo tmp.vbs"') do call set ook=%toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2% 距今天相差 %%i 天&set week=%%i
:del_
del tmp.vbs
goto xinqi
::-----------------------------------------------------------------------------------------
::通过天数得到日期
:tgtian
cls&echo.&echo 当前日期是 %date%&echo.
echo 查询“当前日期之后”的天数请先输入 + 号,如: +10 表示10天以后的日期:
echo.&set /p n= 请输入:
if "%n:~0,1%"=="+" set n=-%n%
>%tmp%\tmp.vbs echo wscript.echo dateadd("d",-%n%,date)
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do (
set y=%%i
set m=%%j
set d=%%k
)
if %m% LSS 10 set m=0%m%
if %d% LSS 10 set d=0%d%
set toDate=%y%%m%%d%
::-----------------------------------------------------------------------------------------
::查询星期
:xinqi
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp2=%%n&&call set %%Tmp2:-==%%
set week=+0
if "%toDate:~0,1%"=="+" goto yihou2
>tmp.vbs echo wscript.echo Weekday(CDate("%toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2%")%week%)
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call set ok=星期%%week%%i%%
goto yiqian2
:yihou2
>tmp.vbs echo wscript.echo Weekday(CDate("%toDate:~1,4%-%toDate:~5,2%-%toDate:~7,2%")%week%)
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call set ok=星期%%week%%i%%
:yiqian2
del tmp.vbs
if "%xuanz%"=="t" goto xst
cls&echo.&echo 今天是 %date%
echo.
if "%toDate:~0,1%"=="+" (
echo 还要过 %ook:~18% 才是您输入的 %ook:~0,10% %ok%
pause>nul&goto loop
)
echo 您输入的 %ook:~0,10% %ok% %ook:~11,5% %ook:~18%
echo.&pause>nul&goto loop
:xst
cls&echo.&echo 今天是 %date%
echo.
if "%n:~0,1%"=="-" (
echo %n:~2% 天以后的日期是 %toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2% %ok%
pause>nul&goto loop
)
echo %n% 天以前的日期是 %toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2% %ok%
pause>nul&goto loop
[ Last edited by 26933062 on 2007-2-10 at 06:07 AM ]
|
|
2007-2-10 18:36 |
|
|
ruisoft
初级用户
积分 93
发帖 57
注册 2007-3-12
状态 离线
|
『第
21 楼』:
还是看不懂!
高手们给一个详解吗?
好像不能返回当前日期的星期值!
[ Last edited by ruisoft on 2008-11-29 at 11:09 ]
|
|
2008-11-28 16:18 |
|
|
sea1112
初级用户
积分 131
发帖 119
注册 2007-6-12 来自 gz
状态 离线
|
『第
22 楼』:
Quote: | Originally posted by 26933062 at 2007-2-6 03:11 AM:
比如20060110
如何通过以上日期判断是星期几? |
|
@echo off
:s
echo 输入日期查看星期?格式[2008-08-08]
set /p n=请输入:
echo %date:~0,10%>bak>nul
echo %n%|date>nul
echo %n% 这天是:%date:~11,14%
type bak|date>nul
echo.
pause&cls&goto s
[ Last edited by sea1112 on 2008-11-28 at 16:52 ]
|
|
2008-11-28 16:37 |
|
|