![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-11-24 08:15 |
47,820 topics / 349,938 posts / today 0 new / 48,298 members |
| DOS批处理 & 脚本技术(批处理室) » Determine the day of the week from the date |
| Printable Version 3,145 / 21 |
| Floor16 anqing | Posted 2007-02-09 07:16 |
| 高级用户 Posts 413 Credits 859 | |
Originally posted by zh159 at 2007-2-9 06:05: |
|
| Floor17 zh159 | Posted 2007-02-09 07:43 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
Originally posted by anqing at 2007-2-8 18:16: That's right, and "tokens=* delims=-" can all be omitted |
|
| Floor18 26933062 | Posted 2007-02-09 14:38 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
This is a batch processing I made to calculate the number of days through dates. It's too bloated. Please experts simplify it. Thanks
@echo off :: Calculate days through dates set kai=0 set wan=0 set dangq=%date:~0,4% set /p n=Please enter the date to query in the format (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% :: Get how many leap years there are 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% is %ts% days different from today echo. echo There are %er% leap years pause>nul [ Last edited by 26933062 on 2007-2-9 at 01:39 AM ] |
|
| Floor19 zh159 | Posted 2007-02-09 14:59 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Played in the past two days
[ Last edited by zh159 on 2007-2-9 at 02:00 AM ] |
|
| Floor20 26933062 | Posted 2007-02-10 18:36 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Thank you everyone for your answers
After summarizing and integrating everyone's methods, I finally made it. Please help take a look and make some changes :: Calculate days by date and display the day of the week :: Calculate date by days and display the day of the week @echo off :loop set xuanz= cls&echo.&echo Press t to use days query, press r or any key to use date query. echo.&set /p xuanz= Please choose: : if "%xuanz%"=="t" goto tgtian cls&echo.&echo Current date is %date%&echo.&set toDate= echo Please enter the date to query in the format (20070101) echo.&echo If you want to query the date "after the current date", please enter the + sign first, such as: (+20080102) echo.&set /p toDate= Please enter: 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 You entered %toDate%. If you want to query the date before the current date, please do not enter the + sign echo.&echo Your input is incorrect, please press any key to re-enter......... 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 You entered %toDate%. If you want to query the date after the current date, please enter the + sign first echo.&echo Your input is incorrect, please press any key to re-enter......... 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% is %date% different by %%i days&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% is %date% different by %%i days&set week=%%i :del_ del tmp.vbs goto xinqi ::----------------------------------------------------------------------------------------- ::Get date by days :tgtian cls&echo.&echo Current date is %date%&echo. echo If you want to query the days "after the current date", please enter the + sign first, such as: +10 means the date 10 days later: echo.&set /p n= Please enter: 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% ::----------------------------------------------------------------------------------------- ::Query day of the week :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 %%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 %%week%%i%% :yiqian2 del tmp.vbs if "%xuanz%"=="t" goto xst cls&echo.&echo Today is %date% echo. if "%toDate:~0,1%"=="+" ( echo It will take %ook:~18% to reach the %ook:~0,10% %ok% you entered pause>nul&goto loop ) echo The %ook:~0,10% %ok% you entered is %ook:~11,5% %ook:~18% echo.&pause>nul&goto loop :xst cls&echo.&echo Today is %date% echo. if "%n:~0,1%"=="-" ( echo The date %n:~2% days later is %toDate:~0,4%-%toDate:~4,2%-%toDate:~6,2% %ok% pause>nul&goto loop ) echo The date %n% days ago is %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 ] |
|
| Floor21 ruisoft | Posted 2008-11-28 16:18 |
| 初级用户 Posts 57 Credits 93 | |
|
Still don't understand!
Can the experts give a detailed explanation? It seems that the week value of the current date cannot be returned! [ Last edited by ruisoft on 2008-11-29 at 11:09 ] |
|
| Floor22 sea1112 | Posted 2008-11-28 16:37 |
| 初级用户 Posts 119 Credits 131 From gz | |
Originally posted by 26933062 at 2007-2-6 03:11 AM: @echo off :s echo Enter date to check the day of the week? Format set /p n=Please enter: echo %date:~0,10%>bak>nul echo %n%|date>nul echo %n% is:%date:~11,14% type bak|date>nul echo. pause&cls&goto s [ Last edited by sea1112 on 2008-11-28 at 16:52 ] |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |