:: GROUNDHOG.BAT :: Groundhog :: :: By Wronski :: (with some recycling from stuff in :: www.chebucto.ns.ca/~ak621/dos/bat.adv.htm :: and Yesterday.bat by Rob van der Woude :: http://www.robvanderwoude.com) :: :: USAGE: groundhog [file] [date] will run [file] set at date [date] :: Default values will be used if no [file] or [date] given @echo off SETLOCAL ::dafault file set file=C:\wherever\whatever.exe ::default date set Fakedate=09/07/2003 if %1a==a goto default set file=%1 if %2a==a goto default set Fakedate=%2 :default SET today=%date:~4,10% date=%Fakedate% CALL %file% :daycount If NOT "%date:~4,10%"=="%Fakedate%" ( SET vardate = %Fakedate% CALL :addday SET Fakedate=%NextDate% SET vardate = %today% CALL :addday SET today=%NextDate% goto daycount ) date=%today% ::restore previous date ENDLOCAL GOTO:EOF :: * * * * * * * * Subroutines * * * * * * * * :addday :: Parse the day SET Day=%date:~7,2% SET Month=%date:~4,2% SET Year=%date:~10,4% SET NexTD= SET NextM= SET NextY= :: Strip leading zeros SET DayS=%Day% IF %Day:~0,1%==0 SET DayS=%Day:~1% SET MonthS=%Month% IF %Month:~0,1%==0 SET MonthS=%Month:~1% :: Calculate next day's date SET /A NextD=%DayS% + 1 SET NextM=%MonthS% SET NextY=%Year% IF %DayS% EQU 31 ( SET NextD=1 Call :ChangeYear ) IF %DayS% EQU 30 ( SET NextY=%Year% CALL :ChangeMonth ) IF "%MonthS%/%DayS%"=="2/28" CALL :LeapYear :: Add leading zeros to NextD and NextM if necessary IF %NextD% LSS 10 SET NextD=0%NextD% IF %NextM% LSS 10 SET NextM=0%NextM% :: Nextday's date in MM/DD/YYYY format SET NextDate=%NextM%/%NextD%/%NextY% GOTO:EOF :ChangeYear IF %MonthS% EQU 12 ( SET NextM=1 SET /A NextY=%Year% + 1 ) ELSE (SET /A NextM=%MonthS%+1) ) GOTO:EOF :ChangeMonth IF %MonthS%==1 ( SET NextD=31 SET NextM=1 SET /A NextY = %Year% ) IF %MonthS%==3 ( SET NextD=31 SET NextM=03 CALL :LeapYear ) IF %MonthS%==4 ( SET NextD=1 SET NextM=05 ) IF %MonthS%==5 ( SET NextD=31 SET NextM=05 ) IF %MonthS%==6 ( SET NextD=1 SET NextM=07 ) IF %MonthS%==7 ( SET NextD=31 SET NextM=07 ) IF %MonthS%==8 ( SET NextD=31 SET NextM=08 ) IF %MonthS%==9 ( SET NextD=1 SET NextM=10 ) IF %Month%==10 ( SET NextD=31 SET NextM=10 ) IF %Month%==11 ( SET NextD=1 SET NextM=12 ) IF %Month%==12 ( SET NextD=31 SET NextM=12 ) GOTO:EOF :LeapYear echo leap :: If the year divisable by 4 then it is a leap year . . . SET /A LeapYear = %Year% / 4 SET /A LeapYear = %LeapYear% * 4 IF NOT %LeapYear% EQU %Year% ( SET NextD=1 SET NextM=3 ) :: . . . unless it is also divisible by 100 . . . SET /A LeapYear = %Year% / 100 SET /A LeapYear = %LeapYear% * 100 IF %LeapYear% EQU %Year% ( SET NextD=1 SET NextM=3 ) :: . . . but when it is divisible by 400 it is a leap year again SET /A LeapYear = %Year% / 400 SET /A LeapYear = %LeapYear% * 400 IF %LeapYear% EQU %Year% ( SET NextD=29 SET NextM=2 ) GOTO:EOF