|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『楼 主』:
请问如何取下个日期时间
使用 LLM 解释/回答一下
用date取时间日期,我现在想要取系统的下一个工作日日期,比如今天星期五20070406,我想取的就是下星期一20070409,如果是星期四20070405的话我要取的就是星期五20070406,不知道如何实现,希望大大们帮忙.
本人不知道如何让日期做算术运算,另外就是不知道如何判断星期的问题.
Using date to get the time and date. I now want to get the next working day date of the system. For example, today is Friday 20070406, and I want to get next Monday 20070409. If it is Thursday 20070405, I need to get Friday 20070406. I don't know how to implement it. I don't know how to do arithmetic operations on dates, and also don't know how to judge the day of the week.
|
|
2007-4-7 06:25 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
dim Wday,today
today=date
Wday=Weekday(now)
Select Case (Wday)
case 1 today=today+1
case 2 today=today+1
case 3 today=today+1
case 4 today=today+1
case 5 today=today+1
case 6 today=today+3
case 7 today=today+2
end select
WScript.echo "下一个工作日是:"&CDate(today)
试试这个?
dim Wday,today
today=date
Wday=Weekday(now)
Select Case (Wday)
case 1 today=today+1
case 2 today=today+1
case 3 today=today+1
case 4 today=today+1
case 5 today=today+1
case 6 today=today+3
case 7 today=today+2
end select
WScript.echo "The next working day is: "&CDate(today)
Try this?
|
|
2007-4-7 11:12 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@echo off & setlocal enabledelayedexpansion
set condate=20070407
set today=%date:~0,4%%date:~5,2%%date:~8,2%
set /a num=%today%-%condate%
set /a num=!num!%%7
if %num%==0 set /a num=!today!+2&goto today
if %num%==1 set /a num=!today!+1&goto today
if %num%==2 set /a num=!today!+1&goto today
if %num%==3 set /a num=!today!+1&goto today
if %num%==4 set /a num=!today!+1&goto today
if %num%==5 set /a num=!today!+1&goto today
if %num%==6 set /a num=!today!+3&goto today
:today
echo 下一个工作日是:!num!
pause
```batch code
@echo off & setlocal enabledelayedexpansion
set condate=20070407
set today=%date:~0,4%%date:~5,2%%date:~8,2%
set /a num=%today%-%condate%
set /a num=!num!%%7
if %num%==0 set /a num=!today!+2&goto today
if %num%==1 set /a num=!today!+1&goto today
if %num%==2 set /a num=!today!+1&goto today
if %num%==3 set /a num=!today!+1&goto today
if %num%==4 set /a num=!today!+1&goto today
if %num%==5 set /a num=!today!+1&goto today
if %num%==6 set /a num=!today!+3&goto today
:today
echo The next working day is: !num!
pause
```
|
|
2007-4-7 21:38 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
没有通用代码..
xp和2000里的格式都不一样。
至于日期计算是算法问题。.和这里无关。
至于星期 %date%里面已经包含了。
There is no universal code..
The formats in XP and 2000 are different.
As for date calculation, it's an algorithm issue. It has nothing to do with here.
As for the day of the week, %date% already contains it.
|

知,不觉多。不知,乃求知 |
|
2007-4-8 06:10 |
|
|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
谢谢wudixin96朋友。2楼是vbs脚本好像可以用,3楼的脚本有问题,如果隔年份就会出问题了~~不知道能不能解决这个问题?或者vbs脚本的变量我怎么在bat脚本下取到,是否可以??
Last edited by lililulula on 2007-4-8 at 04:27 PM ]
Thanks to friend wudixin96. The VBS script on the second floor seems to be usable. There is an issue with the script on the third floor; it will have problems if there are years in between. I wonder if this problem can be solved? Or how I can get the variables of the VBS script in the bat script, is it possible??
Last edited by lililulula on 2007-4-8 at 04:27 PM ]
|
|
2007-4-8 13:58 |
|
|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
自己先顶下 顺便把3楼的脚本消化下~~~
Bump for myself first, and by the way, digest the script on the 3rd floor~~~
|
|
2007-4-9 05:29 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
这么写太麻烦了。。
可以利用系统自带的功能进行分析。。。
假设操作系统为windows xp。。
则以下脚本可以用。。(这里不进行错误判断,现场还原也不对时间判断,23:59:59秒使用时,会使日期返回错误。)
@echo off
set OldDate=%date%
:reInput
echo 请输入你要查询的日期。格式为:2007-04-05。
set /p input=^>
echo %input% | date >nul
if not errorlevel 1 (
echo 下一个工作日是: %date:~11,3%
) else (
goto :reInput
)
echo %OldDate% | date >nul
pause
It's too cumbersome to write like this..
You can use the system's own functions for analysis...
Assume the operating system is Windows XP..
Then the following script can be used. (Here, error judgment is not carried out, and time judgment is not done on the spot. When using 23:59:59 seconds, it will cause the date to return an error.)
@echo off
set OldDate=%date%
:reInput
echo Please enter the date you want to query. The format is: 2007-04-05.
set /p input=>
echo %input% | date >nul
if not errorlevel 1 (
echo The next working day is: %date:~11,3%
) else (
goto :reInput
)
echo %OldDate% | date >nul
pause
|

知,不觉多。不知,乃求知 |
|
2007-4-9 07:52 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
哦。。这个脚本可以查询的日期为 XP 系统支持的任意日期。
如果不在特定时间点使用,则此脚本基本无错。
Oh.. This script can query dates that are any date supported by the XP system. If not used at a specific time point, this script is basically error-free.
|

知,不觉多。不知,乃求知 |
|
2007-4-9 07:55 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我还,没有仔细看楼主的题目。其实也很简单。
我曾经发过关于任意日期运算的帖子,可以查询任意年月日(类似于万年历的)。
不过大家好象都不喜欢,我就把贴删掉了。
日期运算需要定义时间。。
I haven't looked closely at the title of the original poster. Actually, it's also very simple.
I once posted about arbitrary date calculations, which can query any year, month, and day (similar to an almanac).
But everyone didn't seem to like it, so I deleted the post.
Date calculation needs to define time.
|

知,不觉多。不知,乃求知 |
|
2007-4-9 08:05 |
|
|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
flyinspace朋友 你的7楼脚本只是查询输入日期当天是星期几,不过我还是要问下关于echo %input% | date >nul和echo %OldDate% | date >nul两句我有点不懂,后面的| date>nul是把取到的日期置空?但是我单单实验set /p input=:> echo %input% | date>nul输入的日期会修改成为当前系统日期,而脚本中echo %OldDate% | date >nul加上后系统日期便不会修改,具体含义不是很明白,希望flyinspace朋友能告诉我下.
而我的要求是取得系统日期后判断下一个工作日,然后取的日期,3楼的脚本在搁年会出错,不知道有社么办法可以解决.
Friend flyinspace, your script on floor 7 only checks what day of the week the input date is. But I still have questions about the two lines echo %input% | date >nul and echo %OldDate% | date >nul. I don't quite understand. The | date>nul after that is supposed to empty the obtained date? But when I simply test set /p input=:> echo %input% | date>nul, the input date will be modified to the current system date. However, in the script, after adding echo %OldDate% | date >nul, the system date won't be modified. I don't really understand the specific meaning. I hope friend flyinspace can tell me.
And my requirement is to get the system date and then judge the next working day, and get the date. The script on floor 3 will have errors during the year-end, I don't know what methods there are to solve it.
|
|
2007-4-10 00:01 |
|
|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
问题我已经解决,2楼告诉了我怎么做日期算术运算,我从中得到启发,由于2楼的思考方法在脚本运行的时候如果跨年就会出错,所以我直接判断星期字符,就避免了这个问题,脚本如下(2000下):
@echo off
set day=%date:~-10,4%%date:~-5,2%%date:~-2,2%
set date=%date:~-14,3%
if %date%==星期一 set /a nextworkday=%day%+1&goto workday
if %date%==星期二 set /a nextworkday=%day%+1&goto workday
if %date%==星期三 set /a nextworkday=%day%+1&goto workday
if %date%==星期四 set /a nextworkday=%day%+1&goto workday
if %date%==星期五 set /a nextworkday=%day%+3&goto workday
if %date%==星期六 set /a nextworkday=%day%+2&goto workday
if %date%==星期日 set /a nextworkday=%day%+1&goto workday
:workday
echo 下一个工作日是:%nextworkday%
pause
还有一个问题就是为什么多重设置date的时候变量名要是date才有效?比如
set date=%date:~0,10%
set date=%date:-=%
date变量为今天日期20070409
而如果这样却无效
set day=%date:~0,10%
set day=%date:-=%
date日期为2007-04-09,第二句set无效
延迟变量开启也没有帮助
Last edited by lililulula on 2007-4-9 at 12:36 PM ]
The problem has been solved. The 2nd floor told me how to do date arithmetic operations. I got inspiration from it. Because the thinking method of the 2nd floor would be wrong when crossing years during script running, so I directly judge the week character, which avoids this problem. The script is as follows (under 2000):
@echo off
set day=%date:~-10,4%%date:~-5,2%%date:~-2,2%
set date=%date:~-14,3%
if %date%==Monday set /a nextworkday=%day%+1&goto workday
if %date%==Tuesday set /a nextworkday=%day%+1&goto workday
if %date%==Wednesday set /a nextworkday=%day%+1&goto workday
if %date%==Thursday set /a nextworkday=%day%+1&goto workday
if %date%==Friday set /a nextworkday=%day%+3&goto workday
if %date%==Saturday set /a nextworkday=%day%+2&goto workday
if %date%==Sunday set /a nextworkday=%day%+1&goto workday
:workday
echo The next working day is: %nextworkday%
pause
There is another problem: why does the variable name have to be date to be effective when setting date multiple times? For example
set date=%date:~0,10%
set date=%date:-=%
The date variable is today's date 20070409
But if it is like this, it is invalid
set day=%date:~0,10%
set day=%date:-=%
The date is 2007-04-09, and the second set is invalid
Enabling delayed variables doesn't help
Last edited by lililulula on 2007-4-9 at 12:36 PM ]
|
|
2007-4-10 01:23 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
你的系统是windows 2000。。
使用我的脚本时应该会有错误提示:没有操作数。
set date=%date:~-14,3%
另外,最好不要定义已有的环境变量。
隔年出错是因为没有对年份进行判断。(有闰年、平年的区别)而且每年的第一个星期都会有偏差。。。
还有,我怎么看,这个脚本都应该有问题的。。
即使在2007年内,也肯定有几天会出现错误。
时间判断不够严密。
Your system is Windows 2000.
When using my script, there should be an error prompt: no operand.
set date=%date:~-14,3%
Also, it is best not to define existing environment variables.
The error in the next year is because there is no judgment on the year. (There are differences between leap years and common years) And there will be deviations in the first week of each year...
Also, no matter how I look at it, this script should have problems.
Even within 2007, there will definitely be some days with errors.
The time judgment is not strict enough.
|

知,不觉多。不知,乃求知 |
|
2007-4-10 02:06 |
|
|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
flyinspace朋友你说的2楼脚本确实有问题,我按照星期判断的话,取当天星期,字符串比较,我想应该不会有问题了,因为我取的就是系统后面的星期,然后判断的话,情况也就7种啊~~~~另外你说不要定义已有的黄鲸变量是什么意思??不是很明白
Last edited by lililulula on 2007-4-9 at 01:28 PM ]
Friend flyinspace, the script you mentioned for the second floor does have issues. If I judge by the day of the week, taking the current day of the week and comparing strings, it should be fine because I'm just taking the system's subsequent day of the week, and there are only 7 possible cases when judging~~~~ Also, I don't quite understand what you mean by not defining existing Huangjing variables?
Last edited by lililulula on 2007-4-9 at 01:28 PM ]
|
|
2007-4-10 02:26 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
建议你把批处理的教程先看一遍。
你的问题我给你指出吧。
假设 2007年4月30日。
则怎么判断?
It is suggested that you read the batch processing tutorial first.
I will point out your problem.
Assume it is April 30, 2007.
Then how to judge?
|

知,不觉多。不知,乃求知 |
|
2007-4-10 03:08 |
|
|
lililulula
中级用户
  
积分 302
发帖 138
注册 2007-3-29
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
你一说倒真是这样,我后来也看了2楼的脚本也有着个问题,我的脚本也有这个问题,不过3楼的vbs脚本没问题,有wekekday这个自带参数~~~~,看来考虑问题没考虑全面,谢谢楼上提醒,我想知道有办法解决这个问题吗?或是vbs最后的&CDate(today),bat脚本要取这个变量值该怎么取???
You're right when you say that. Later I also saw that the script on floor 2 has this problem, and my script also has this problem. However, the VBS script on floor 3 is okay, as it has the built-in parameter wekekday~~~~ It seems I didn't consider the problem comprehensively. Thanks for the reminder from the upstairs. I want to know if there's a way to solve this problem? Or how to get the value of the variable in the bat script from the final &CDate(today) in VBS???
|
|
2007-4-10 03:59 |
|