我目前有这个:
for /F "tokens=2 delims==." %%I in ('%SystemRoot%\System32\wbem\wmic.exe OS GET LocalDateTime /VALUE') do set "FileNameDate=%%I"
set "FileNameDate=%FileNameDate:~0,4%-%FileNameDate:~4,2%-%FileNameDate:~6,2%"
它用于以与另一个批处理文件用来查找过去日期的文件上的日期格式匹配的格式来获取日期。我想再次使用它,但是我想通过减去2年来更改日期。因此,而不是输出:
2018-11-29
我想得到:
2016-11-29
了解吗?
我该怎么做?
答案 0 :(得分:3)
通过批处理文件很简单:
@echo off
setlocal
for /F "tokens=2 delims==." %%I in ('%SystemRoot%\System32\wbem\wmic.exe OS GET LocalDateTime /VALUE') do set "FileNameDate=%%I"
set "FileNameDate=%FileNameDate:~0,8%"
REM Activate next line for test:
REM set /P "FileNameDate=YYYYMMDD: "
set /A "FileNameDate-=20000+!(1%FileNameDate:~4,4%-10229)"
set "FileNameDate=%FileNameDate:~0,4%-%FileNameDate:~4,2%-%FileNameDate:~6,2%"
echo %FileNameDate%
测试输出:
YYYYMMDD: 20181129
2016-11-29
YYYYMMDD: 20160229
2014-02-28