Laserfiche WebLink
Easily Add or Subtract Days from a Date with a Windows Batch Script <br /> <br />Here's a solution I came up with for calculating date (add or subtract) with a batch script. Set the variables accordingly for your needs and then adjust the logic as need for your needs <br /> as well. This works very well for my needs and it's all contained to the same one batch script without too much logic. <br /> <br />To add: You can also use this script to add a number of days to the current date by deleting the minus (-) symbol from the below batch script in the :DynamicVBSScriptBuild routine, so <br /> where you see this,-%MinusDay%, you simple remove the minus symbol to get ,%MinusDay%, on each of those lines and now the MinusDay= variable value will equal the number of days you <br /> want to add. <br /> <br />Important Note: It seems that five 9's (99999) is the limit on the batch script when subtracting with the MinusDays= value. It also seems that six 9's (999999) is the limit on the batch <br /> script when adding with the MinusDays= value. <br /> <br /> <br />Batch Script <br /> <br />@ECHO ON <br /> <br />::// Minus days is the number of days to subtract from the CURRENT DAY i.e. 2 for minus 2 days or 99999 for minus 99999 days from when it's run <br />SET MinusDay=2 <br /> <br />:: This calls the temp vbs script routine that will be used to set YYYY-MM-DD values for the subtracted days date you specify <br />CALL :DynamicVBSScriptBuild <br /> <br />FOR /F "TOKENS=*" %%A IN ('cscript//nologo "%YYYYTmpVBS%"') DO SET YYYY=%%A <br />FOR /F "TOKENS=*" %%A IN ('cscript//nologo "%MMTmpVBS%"') DO SET MM=%%A <br />FOR /F "TOKENS=*" %%A IN ('cscript//nologo "%DDTmpVBS%"') DO SET DD=%%A <br /> <br />::// Set your web server log file path in the below variable <br />SET WebServerLogPath=C:\WebServer\Logs <br /> <br />::// Set web server log file name where YYYY MM DD variables are set to the values after the day numbers setup above are subtracted <br />SET YYYY=%YYYY% <br />SET MM=%MM% <br />SET DD=%DD% <br /> <br />ECHO %YYYY%%MM%%DD% <br />PAUSE <br /> <br />GOTO EOF <br /> <br />:DynamicVBSScriptBuild <br />SET YYYYTmpVBS=%temp%\~tmp_yyyy.vbs <br />SET MMTmpVBS=%temp%\~tmp_mm.vbs <br />SET DDTmpVBS=%temp%\~tmp_dd.vbs <br />IF EXIST "%YYYYTmpVBS%" DEL /Q /F "%YYYYTmpVBS%" <br />IF EXIST "%MMTmpVBS%" DEL /Q /F "%MMTmpVBS%" <br />IF EXIST "%DDTmpVBS%" DEL /Q /F "%DDTmpVBS%" <br />ECHO dt = DateAdd("d",-%MinusDay%,date) >> "%YYYYTmpVBS%" <br />ECHO yyyy = Year(dt) >> "%YYYYTmpVBS%" <br />ECHO WScript.Echo yyyy >> "%YYYYTmpVBS%" <br />ECHO dt = DateAdd("d",-%MinusDay%,date) >> "%MMTmpVBS%" <br />ECHO mm = Right("0" ^& Month(dt),2) >> "%MMTmpVBS%" <br />ECHO WScript.Echo mm >> "%MMTmpVBS%" <br />ECHO dt = DateAdd("d",-%MinusDay%,date) >> "%DDTmpVBS%" <br />ECHO dd = Right("0" ^& Day(dt),2) >> "%DDTmpVBS%" <br />ECHO WScript.Echo dd >> "%DDTmpVBS%" <br />GOTO EOF