我正在尝试将固定日期与当前系统日期进行比较。我想检查当前日期是否大于或等于固定日期。示例:
@ECHO OFF
set fixedDate=27-09-2018
set current=%date%
if %current% GEQ %fixedDate% (goto there) else (goto here)
:here
echo "do nothing"
:there
echo "yes run it"
"do nothing"
"yes run it"
以上代码无效。关于我在哪里做错的任何建议?在此先感谢:)
我尝试过这样:
@ECHO OFF
set FixedDate=27-09-2018
set current=%date%
set "sdate1=%current:~-4%%current:~3,2%%current:~0,2%"
set "sdate2=%FixedDate:~-4%%FixedDate:~3,2%%FixedDate:~0,2%"
if %sdate1% GEQ %sdate2% (goto there) else (goto here)
:here
echo "do nothing"
:there
echo "yes run it"
也不起作用。
输出:
"yes run it"
答案 0 :(得分:1)
您可以使用了解日期的PowerShell。
SET "REFDATE=2018-07-04"
FOR /F %%a IN ('powershell -NoProfile -Command "([Datetime]'%REFDATE%') -gt (Get-Date)"') DO (SET "COMPRESU=%%a")
ECHO %COMPRESU%
IF /I "%COMPRESU%" == "True" (GOTO DoTrue) ELSE (GOTO DoFalse)
:DoTrue
ECHO Doing TRUE
GOTO AfterDateTest
:DoFalse
ECHO Doing FALSE
:AfterDateTest
或者,您可以在if中执行命令。
FOR /F %%a IN ('powershell -NoProfile -Command "([Datetime]'%REFDATE%') -gt (Get-Date)"') DO (SET "COMPRESU=%%a")
IF /I "%COMPRESU%" == "true" (truecmd.exe) ELSE (falsecmd.exe)