Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
December 15, 2005
In tip 0721, I calculated the difference between two dates.
In tip 9229, I calculated the difference between two date/times?
I have scripted DateDiff.bat to calculate the difference between two short dates.
The syntax for using DateDiff.bat is:
[call] DateDiff ShortDate1 ShortDate2 Days
Where:
ShortDate1 First date, in your date format, like MM/DD/YYYY. Quotes are NOT allowed.ShortDate2 Second date, in your date format, like MM/DD/YYYY. Quotes are NOT allowed.Days is a call directed numeric environment variable that will contain the difference: Days = ShortDate1 - ShortDate2. Days may be negative.
To calculate the number of days till Christmas, call XMAS 12/25/2006 Days, where XMAS.BAT contains:
@echo offif {%2}
{} @echo Syntax: XMAS DateOfXmas Diff&goto :EOFsetlocalcall DatePorM 0 Todaycall DateDiff %1 %Today% Diff@echo %Diff%endlocal&set /a %2=%Diff%
DateDiff.bat contains:
@echo offif {%3}{} @echo Syntax: DateDiff ShortDate1 ShortDate2 Days&goto :EOFif exist "%TEMP%DateDiff.vbs" goto doit@echo Dim dDate1, dDate2, dDiff>"%TEMP%DateDiff.vbs"@echo dDate1 = CDate(WScript.Arguments(0))>>"%TEMP%DateDiff.vbs"@echo dDate2 = CDate(WScript.Arguments(1))>>"%TEMP%DateDiff.vbs"@echo dDiff = dDate1 - dDate2>>"%TEMP%DateDiff.vbs"@echo WScript.Echo dDiff>>"%TEMP%DateDiff.vbs":doitfor /f "Tokens=*" %%d in ('cscript //nologo "%TEMP%DateDiff.vbs" %1 %2') do ( set %3=%%d)
You May Also Like