批处理bat计算前N个月第一天的日期
【方案一】BAT+date.exe(GNU)
@echooff
rem调用GNUforWin32的date.exe
set"gnuDate=C:/test/date.exe"
rem指定月数
setMonthsAgo=1
for/f%%ain('%gnuDate%-d"%MonthsAgo%monthsago""+%%Y-%%m-01"')do(
set"DstDate=%%a"
)
)
echo,%DstDate%
pause
【方案二】BAT+VBS
@echooff
rem指定月数
setMonthsAgo=2
>"%temp%/DateCalculate.vbs"echostrLastDate=DateAdd("m",-%MonthsAgo%,Date)
>>"%temp%/DateCalculate.vbs"echostrFmtDate=Right(Year(strLastDate),4)^&Right("0"^&Month(strLastDate),2)^&"01"
>>"%temp%/DateCalculate.vbs"echoWScript.EchostrFmtDate
for/f%%ain('cscript/nologo"%temp%/DateCalculate.vbs"')do(
set"DstDate=%%a"
)
setDstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
echo,%DstDate%
pause
热门推荐
10 古风祝福语 唯美简短结婚
11 送偶像生日祝福语简短
12 集体生日祝福语简短的
13 中秋祝福语简短女朋友
14 离职送别文案祝福语简短
15 女士简短祝福语大全集
16 节日祝福语简短中秋暧昧
17 关于糖果的祝福语简短
18 加油冬奥祝福语英文简短