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:

<b>ShortDate1</b> First date, in your date format, like MM/DD/YYYY. Quotes are <b>NOT</b> allowed.

<b>ShortDate2</b> Second date, in your date format, like MM/DD/YYYY. Quotes are <b>NOT</b> allowed.


<b>Days</b>       is a <a href="/article/jsifaq/jsi-tip-8293-how-can-i-return-the-date-that-is-plus-or-minus-n-days-from-today-.aspx">call directed numeric environment variable</a> that will contain the difference:
           <b>Days</b> = <b>ShortDate1</b> - <b>ShortDate2</b>.
           <b>Days</b> may be negative.

Example

To calculate the number of days till Christmas, call XMAS 12/25/2006 Days, where XMAS.BAT contains:
@echo off
if \{%2\}<h1>
<a name="_echo_Syntax_XMAS_DateOfXmas_Diff_amp_goto_EOF_setlocal_call_a_href_article_jsifaq_jsi_tip_8293_how_can_i_return_the_date_that_is_plus_or_minus_n_days_from_today_aspx_b_DatePorM_b_a_0_Today_call_DateDiff_1_Today_Diff_echo_Diff_endlocal_amp_set_a_2_Diff_pre_font_size_1_b_DateDiff_bat_b_font_contains_pre_echo_off_if_3_">\{\} @echo Syntax: XMAS DateOfXmas Diff&goto :EOF
setlocal
call </a><a href="/article/jsifaq/jsi-tip-8293-how-can-i-return-the-date-that-is-plus-or-minus-n-days-from-today-.aspx"><b>DatePorM</b></a> 0 Today
call DateDiff %1 %Today% Diff
@echo %Diff%
endlocal&set /a %2=%Diff%</h1>
DateDiff.bat contains:
@echo off
if \{%3\}\{\} @echo Syntax: DateDiff ShortDate1 ShortDate2 Days&goto :EOF
if 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"
:doit
for /f "Tokens=*" %%d in ('cscript //nologo "%TEMP%\DateDiff.vbs" %1 %2') do (
 set %3=%%d
)