(view source code of groundhog.bat as plain text)
:: 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 fileset file=C:\wherever\whatever.exe
::default dateset Fakedate=09/07/2003
if %1a==a goto default
set file=%1
if %2a==a goto default
set Fakedate=%2
:defaultSET today=%date:~4,10%
date=%Fakedate%
CALL %file%
:daycountIf 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 daySET Day=%date:~7,2%
SET Month=%date:~4,2%
SET Year=%date:~10,4%
SET NexTD=
SET NextM=
SET NextY=
:: Strip leading zerosSET 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 dateSET /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 necessaryIF %NextD% LSS 10 SET NextD=0%NextD%
IF %NextM% LSS 10 SET NextM=0%NextM%
:: Nextday's date in MM/DD/YYYY formatSET NextDate=%NextM%/%NextD%/%NextY%
GOTO:EOF
:ChangeYearIF %MonthS% EQU 12 (
SET NextM=1
SET /A NextY=%Year% + 1
) ELSE (SET /A NextM=%MonthS%+1)
)GOTO:EOF
:ChangeMonthIF %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
:LeapYearecho 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
page last modified: 2025-10-11; loaded in 0.0078 seconds