gpt4 book ai didi

date - 昨天日期使用 VBS 代码和批处理文件(格式 : YYYY_MM_DD)

转载 作者:行者123 更新时间:2023-12-05 01:30:45 25 4
gpt4 key购买 nike

使用批处理我想创建一个包含昨天日期的变量,正是我需要这种格式:“YYYY_MM_DD”

我成功拥有这种格式:YYYYMMDD

我创建了一个 vbs 文件“yesterday.vbs”:

d = date() - 1
wscript.echo year(d) * 10000 + month(d) * 100 + day(d)

在我的批处理文件中,我调用了我的代码:

REM ----------------   Yesterday VAR  ---------------------

for /f %%a in ('cscript //nologo yesterday.vbs') do set yesterday=%%a

我想要这种格式:

YYYY_MM_DD

提前致谢,

最佳答案

将您的任务拆分为两个单独的文件,就像您所做的那样:

:

@Echo Off
For /F %%A In ('CScript //NoLogo "yesterday.vbs"') Do Set "Yesterday=%%A"
Echo(%Yesterday%
Pause

:

dtmYesterday = DateAdd("d", -1, Now())
strDate = Year(dtmYesterday) & "_" & Right("0" & Month(dtmYesterday), 2) _
& "_" & Right("0" & Day(dtmYesterday), 2)
WScript.Echo strDate

如果您想创建 来自您的 ,运行它,然后删除它:

@Echo Off
( Echo dtmYesterday = DateAdd("d", -1, Now(^)^)
Echo strDate = Year(dtmYesterday^) ^& "_" ^& Right("0" ^& Month(dtmYesterday^), 2^) ^& "_" ^& Right("0" ^& Day(dtmYesterday^), 2^)
Echo WScript.Echo strDate)>"yesterday.vbs"
For /F %%A In ('CScript //NoLogo yesterday.vbs') Do Set "Yesterday=%%A"
Del "yesterday.vbs"
Echo(%Yesterday%
Pause

或者,您仍然可以使用 ,但将其直接嵌入到您的 :

<!-- :
@Echo Off
For /F %%A In ('CScript //NoLogo "%~f0?.wsf"') Do Set "Yesterday=%%A"
Echo(%Yesterday%
Pause
GoTo :EOF
-->
<Job><Script Language="VBScript">
dtmYesterday = DateAdd("d", -1, Now())
strDate = Year(dtmYesterday) & "_" & Right("0" & Month(dtmYesterday), 2) _
& "_" & Right("0" & Day(dtmYesterday), 2)
WScript.Echo strDate
</Script></Job>


说了这么多,我建议你忘记 , 并使用 来自您的 而是:

@Echo Off
For /F %%A In ('PowerShell -NoP "(Get-Date).AddDays(-1).ToString('yyy_MM_dd')"'
)Do Set "Yesterday=%%A"
Echo(%Yesterday%
Pause

关于date - 昨天日期使用 VBS 代码和批处理文件(格式 : YYYY_MM_DD),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58013153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com