中国DOS联盟论坛

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-09-29 23:30
47,813 topics / 349,918 posts / today 0 new / 48,278 members
DOS批处理 & 脚本技术(批处理室) » Determine the day of the week from the date
Printable Version  2,793 / 21
Floor1 26933062 Posted 2007-02-06 03:11
银牌会员 Posts 879 Credits 2,268
For example, 20060110
How to determine what day of the week it is based on the above date?
Floor2 namejm Posted 2007-02-06 03:24
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Here's an idea: First, determine a date for which you already know what day of the week it is. Then calculate the difference in days between 20060110 and that date. Then divide the difference by 7 and take the remainder - the key point is calculating the difference between the two dates, which is transformed back to the classic old topic: What day of the week was N days before a certain date?
Floor3 26933062 Posted 2007-02-06 05:22
银牌会员 Posts 879 Credits 2,268
I can calculate the date n days ago, but just can't calculate the day of the week.
For example, today is 20070205 Monday, the date n days ago is 20061210.
How to calculate it?
How to subtract 20061210 from 20070205?
Floor4 everest79 Posted 2007-02-06 08:26
金牌会员 Posts 1,127 Credits 2,564
The moderator's statement is quite right. First of all, you need to have a reference object. The rest is to convert the date interval into decimal days, subtract 7 minus the reference week, and then divide by 7 to find the remainder.
Floor5 redtek Posted 2007-02-06 09:23
金牌会员 Posts 1,147 Credits 2,902
Another alternative day-of-the-week query: )



  1. @ echo off && setlocal
  2. :: Redtek.2006 bbs.cn-dos.net Query what day of the week a certain year/month/day is



  3. set /p setDate=Please enter the date to query: (Format: year-month-day)


  4. :: Backup current date and set new date

  5. for /f %%i in ('date/t') do set "Current date backup=%%i"
  6. echo %setDate%|date >nul


  7. :: Display the queried date and restore the current date to the backup date

  8. echo. && echo The detailed information of the date you want to query is: %date% ] && echo.
  9. echo %Current date backup%|date >nul




  10. Pause
Redtek@sweetmeet.comPosted on: 2007-02-05 20:26



Note: Do not use this code on computers such as servers that are closely connected to the date.

  Because the implementation principle is to first back up the current date, then set the specified date, use the system %date% to get the day of the week, and then restore the date before the calculation.

  If some date-sensitive programs are installed on the computer, such as: JCreator pro for Java development and other sensitive software, if the date is changed to the past, even if it is changed back, it has become invalid.
Floor6 anqing Posted 2007-02-06 09:38
高级用户 Posts 413 Credits 859
Brother upstairs, just one word, "Like"
Floor7 zh159 Posted 2007-02-06 14:39
金牌会员 Posts 1,467 Credits 3,687
Using the newly learned VBS


Add one modified according to floor 9:


[ Last edited by zh159 on 2007-2-6 at 03:07 PM ]
Floor8 26933062 Posted 2007-02-06 16:29
银牌会员 Posts 879 Credits 2,268
The method on the 5th floor is indeed good, but it seems a bit less perfect to change the system time. Do you all have any other good ideas?
Floor9 112183883 Posted 2007-02-06 17:55
初级用户 Posts 31 Credits 128
Why not use VBS?
Floor10 NaturalJ0 Posted 2007-02-06 21:16
银牌会员 Posts 533 Credits 1,181
I remember there was a formula in the Olympiad in Mathematics when I was a child, and I can check it again.
Floor11 26933062 Posted 2007-02-08 16:40
银牌会员 Posts 879 Credits 2,268
The problem of getting the difference between two dates has been solved. Now the problem is how to determine the day of the week?
//For example, given Thursday, February 8, 2007, how to determine the day of the week 18 days ago?
That is, how to subtract 1 or 2 from the current day of the week...?

[ Last edited by 26933062 on 2007-2-8 at 03:47 AM ]
Floor12 anqing Posted 2007-02-08 22:01
高级用户 Posts 413 Credits 859
Give you a boost, it's getting more challenging
Floor13 zh159 Posted 2007-02-09 05:23
金牌会员 Posts 1,467 Credits 3,687
Originally posted by 26933062 at 2007-2-8 03:40:
The difference between two dates has been solved. Now the problem is how to determine the day of the week?
// For example, given 2007/02/08/Thursday, how to determine the day of the week 18 days ago?
That is, how to subtract 1 or 2 from the current day of the week..........?

...

Floor14 slore Posted 2007-02-09 06:00
铂金会员 Posts 2,478 Credits 5,212
MsgBox WeekdayName(Weekday(CDate(Now)))
Floor15 zh159 Posted 2007-02-09 06:05
金牌会员 Posts 1,467 Credits 3,687
Borrowing from the above:
MsgBox WeekdayName(Weekday(CDate(Now)-18))

+ - number of days



[ Last edited by zh159 on 2007-2-8 at 06:42 PM ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023