My WebLink
|
Help
|
About
|
Sign Out
Home
Add or Subtract Days from a Date
CityHall
>
City Clerk
>
City Council
>
Agreements
>
Rick's System
>
Add or Subtract Days from a Date
Metadata
Thumbnails
Annotations
Entry Properties
Last modified
12/13/2022 1:44:48 PM
Creation date
12/13/2022 1:43:17 PM
Metadata
Fields
Template:
CM City Clerk-City Council
CM City Clerk-City Council - Document Type
Agreement
Retention
PERM
There are no annotations on this page.
Document management portal powered by Laserfiche WebLink 9 © 1998-2015
Laserfiche.
All rights reserved.
Page 1 of 1
PDF
Print
Pages to print
Enter page numbers and/or page ranges separated by commas. For example, 1,3,5-12.
After downloading, print the document using a PDF reader (e.g. Adobe Reader).
Download electronic document
View images
View plain text
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
The URL can be used to link to this page
Your browser does not support the video tag.