Page 1 of 1

Need help with a date less than today script

Posted: 26 Mar 2009 09:37
by billbob
I'm trying to add a date check to script I have written. what I need is..example

If %DATE% is less than this %DATE% goto end else continue..

I'm sending a .bat file to some users desktop but I do not want them to run it until a specific date, but you know they will! I need the script to run if the date is greater than April 17 for instance but not run if less than April 17th?

Thanks!!! :wink:

Posted: 26 Mar 2009 14:03
by RElliott63
Here's a start --

Code: Select all

Set "WD=04/17/2009"
Set date.MM=%WD:~0,2%
Set date.DD=%WD:~3,2%
Set date.YY=%WD:~6,4%

call :date2jdate date.JUL1 "%date.YY%" "%date.MM%" "%date.DD%"

Set "WD=%Date%"
Set date.MM=%WD:~0,2%
Set date.DD=%WD:~3,2%
Set date.YY=%WD:~6,4%

call :date2jdate date.JUL2 "%date.YY%" "%date.MM%" "%date.DD%"

Set /a Result=date.JUL1-date.JUL2

If /I [%Result%] GTR [0] Goto NotSoFast

:: Execute your code here
Goto Exit

:NotSoFast
Cls
Echo It's too early!

:Exit
Goto:EOF

:date2jdate
set YYYY=%~2
set MM=%~3
set DD=%~4
set /a I=%YYYY%
set /a J=%MM%
set /a K=%DD%
set /a JD=K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12)/12-3*((I+4900+(J-14)/12)/100)/4

( ENDLOCAL & REM RETURN VALUES
    IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
)