批处理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 红包祝福语简短10字
18 周六早晨祝福语简短