//////////////////////////////////////////////////////////////////////////////// // // Determine the date xx number of days ago. // Number of days is passed as a command line parameter, // else the default of 30 is used. // // Example: TMRUN BACKDATE.TSK 180 // // Display the date 180 days ago // // Note: Accuracy limited to the first Leap Year (+/- a few years). // //////////////////////////////////////////////////////////////////////////////// // Check if number of days was passed as command line parameter else use 30 IF "%0"=="" THEN DEFINE %0 30 // This is simple logic manipulation to insure that the format of // the %0 variable is at least two digits DEFINE %9 00 DEFINE %9 %9+=%0 DEFINE %0 %9 // This is simple logic manipulation to insure that the format of the // adjusted day of month variable %1 is the same as that of %0 before // setting %1 to the current day of the month value DEFINE %1 %0 DEFINE %1 %1-=%0 DEFINE %1 %1+=%DAY% // The month and year definitions do not require such logic manipulation DEFINE %2 %MONTH% DEFINE %3 %YEAR% // While the number of days past is greater than the adjusted day of month value WHILE "%0">"%1" // Decrement the month DEFINE %2 %2-=01 // If the decremented month is zero IF "%2"=="00" // Reset the month to 12 DEFINE %2 12 // Decrement the year DEFINE %3 %3-=0001 ENDIF // Adjust the day by the number of days in the previous (decremented) month IF %2==01 OR %2==03 OR %2==05 OR %2==07 OR %2==08 OR %2==10 OR %2==12 DEFINE %1 %1+=31 ELSEIF %2==04 OR %2==06 OR %2==09 OR %2==11 DEFINE %1 %1+=30 ELSE DEFINE %9 00 // Check if the Year is a base Leap Year (Year mod 4 yield %9==0) CALC %9 %3-((%3/4)*4) IF %9==00 // Year mod 4 indicates possible Leap Year // However, centuries (Year mod 100) are not Leap Years UNLESS 2000 CALC %9 %3-((%3/100)*100) // If not century (Year mod 100 yields %9>00) or Year==2000 then Leap Year IF %9>00 OR %3==2000 DEFINE %1 %1+=29 ELSE DEFINE %1 %1+=28 END ELSE DEFINE %1 %1+=28 END ENDIF LOOP // Next, subtract the number of days from the adjusted day of month DEFINE %1 %1-=%0 // Then use simple logic manipulation to reformat the adjusted day of month DEFINE %9 00 DEFINE %9 %9+=%1 DEFINE %1 %9 // Finally, display the adjusted date ECHO. ECHO %0 days ago was: %2/%1/%3 (MM/DD/YYY) ECHO.