中国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-08-02 02:27
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » How to get the current day of the week in a bat file?
Printable Version  2,369 / 4
Floor1 gskys123 Posted 2006-09-10 10:45
初级用户 Posts 7 Credits 26 From 四川
To write an automatic shutdown batch file and get the current day of the week in a batch script to make different shutdown time settings for different days of the week, you can use the following method:

```batch
@echo off
for /f "tokens=2 delims==" %%a in ('wmic os get LocalDateTime /value') do set "dt=%%a"
set "weekday=%dt:~8,2%"
if "%weekday%"=="05" (
echo Today is Friday, execute a.bat
call a.bat
) else if "%weekday%"=="06" (
echo Today is Saturday, execute a.bat
call a.bat
) else (
echo Today is not Friday or Saturday, execute b.bat
call b.bat
)
```

Explanation: First, use `wmic os get LocalDateTime /value` to get the system's date and time information, then extract the day of the week part (`%dt:~8,2%` gets the 9th and 10th characters, which represent the day of the week in the format like "05" for Friday, "06" for Saturday). Then make judgments based on the value of the `weekday` variable, and execute different batch files accordingly.

Please note that the above code is a basic example, and you can adjust it according to your specific actual needs.

[ Last edited by gskys123 on 2006-9-10 at 22:13 ]
Floor2 vkill Posted 2006-09-11 00:55
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
If you echo %date% shows like: 2006-09-10 Sunday, then the following can

echo %date% |find "Friday" && call a.bat ||call b.bat
echo %date% |find "Saturday" && call a.bat ||call b.bat
Floor3 fastslz Posted 2006-09-11 02:13
铂金会员 Posts 2,315 Credits 5,493 From 上海
View Help
HH ntcmds.chm::/net_user.htm




Examples
To display a list of all user accounts on the local computer, type:

net user

To view information about the user account jimmyh, type:

net user jimmyh

To add a user account for Jay Jamison, with logon permissions from Monday to Friday, 8 AM to 5 PM (no spaces in the time specification), and a forced password (jayj) and full name for the user, type:

net user jayj /add /passwordreq:yes /times:monday-friday,8am-5pm/fullname:"Jay Jamison"

To set johnsw's logon time using 24-hour notation (8 AM to 5 PM), type:

net user johnsw /time:M-F,08:00-17:00

To set johnsw's logon time using 12-hour notation (8 AM to 5 PM), type:

net user johnsw /time:M-F,8am-5pm

To specify marysl's logon time as 4 AM to 5 PM on Monday, 1 PM to 3 PM on Tuesday, and 8 AM to 5 PM on Wednesday to Friday, type:

net user marysl /time:M,4am-5pm;T,1pm-3pm;W-F,8:00-17:00
Floor4 htysm Posted 2006-09-12 02:30
高级用户 Posts 415 Credits 866
In fact, using the day of the week to set different shutdown times is only useful for general users. Anyone with a little computer knowledge knows that you can change the date by entering the BIOS. Unless you also want to set a password for the BIOS.
Floor5 electronixtar Posted 2006-09-12 04:17
铂金会员 Posts 2,672 Credits 7,493
Wow, the person upstairs can even think of this trick, I'm impressed

P.S. It seems there's a time synchronization feature in Windows that can be used to prevent the method the person upstairs used
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023