China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 12:13
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Determine the day of the week from the date View 2,406 Replies 21
Floor 16 Posted 2007-02-09 07:16 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Originally posted by zh159 at 2007-2-9 06:05:
Borrow from the above:
MsgBox WeekdayName(Weekday(CDate(Now)-18))

+ - number of days

@echo off
:loop
cls
echo.
set input=
set week=+0
set /p input= Please enter the date (format: 200 ...






The above delims=- sentence should not be used
Floor 17 Posted 2007-02-09 07:43 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by anqing at 2007-2-8 18:16:

The above delims=- part should not be used


That's right, and "tokens=* delims=-" can all be omitted
Floor 18 Posted 2007-02-09 14:38 ·  中国 湖南 长沙 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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 ]
Floor 19 Posted 2007-02-09 14:59 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Played in the past two days


@echo off
:loop
cls
echo.
set toDate=
set /p toDate= Please enter the date (format: 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% is %%%%i days away from today
del tmp.vbs
echo.
pause
goto loop


[ Last edited by zh159 on 2007-2-9 at 02:00 AM ]
Floor 20 Posted 2007-02-10 18:36 ·  中国 湖南 长沙 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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 ]
Floor 21 Posted 2008-11-28 16:18 ·  中国 云南 丽江 古城区 电信
初级用户
★★
Credits 93
Posts 57
Joined 2007-03-12 12:04
19-year member
UID 81503
Gender Male
Status Offline
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 ]
Floor 22 Posted 2008-11-28 16:37 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 131
Posts 119
Joined 2007-06-12 22:50
19-year member
UID 91125
Gender Male
From gz
Status Offline
Originally posted by 26933062 at 2007-2-6 03:11 AM:
For example, 20060110
How to determine the day of the week through the above date?


@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 ]
Forum Jump: