bat之獲取指定幾個月前的月份資訊

mobox發表於2020-05-27

@echo off

rem 指定幾個月數前

set MonthsAgo=2

>"%temp%/DateCalculate.vbs" echo strLastDate=DateAdd("m", -%MonthsAgo%, Date)

>>"%temp%/DateCalculate.vbs" echo strFmtDate=Right(Year(strLastDate),4) ^& Right("0" ^& Month(strLastDate),2) ^& "01"

>>"%temp%/DateCalculate.vbs" echo WScript.Echo strFmtDate

for /f %%a in ('cscript /nologo "%temp%/DateCalculate.vbs"') do (

    set "DstDate=%%a"

)

set DstDate=%DstDate:~0,4%%DstDate:~4,2%

echo,%DstDate%

pause


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28660496/viewspace-2694605/,如需轉載,請註明出處,否則將追究法律責任。

相關文章