Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Date Difference, passing dates in several formats

Aug
1,954
71
Here's a library function that uses the script command, the tcommand() interface, and VBScript, to determine the number of years (full and part) given a date by the user;
Code:
DateDiff {
@setlocal
@echo off
set dest=%temp\vb.vbs

set theDate=%1

if defined theDate (
::NEXT SENTENCE
) else (
set theDate=%_isodate
)

>%dest echo TakeCommand.tcommand("echo " + CStr(DateDiff("d", "%theDate", Now) / 365.25))

set _DateDiff=%@execstr[script %dest]

echo %_DateDiff

endlocal _DateDiff
}
Example usage;
Code:
e:\utils>datediff 11/1/1960
61.1498973305955

e:\utils>datediff 1960-11-1
61.1498973305955

e:\utils>datediff `November 1, 1960`
61.1498973305955

e:\utils>echo %_datediff
61.1498973305955
Note well that the passed date, in this case, November 1, 1960, can be passed in several formats.

That is, VBScript (usually) has the intelligence to determine the date format entered by the user.

Ref: DateDiff - VBScript

The DateDiff library function also saves the result in the _datediff environment variable, for use else where in TCC, either from the command line, or a .BTM

Joe
 
Last edited:
Back
Top