JSI Tip 8252. DATEX freeware can perform limited date arithmetic.
July 13, 2004
Bill Stewart's DATEX can perform limited date arithmetic.
When you type DATEX /?, you receive:
DATEX 1.0 - (C) 2004 by Bill Stewart ([email protected])Usage: DATEX [-d date] [-f format] [-i num] [-o offset] [-t]-d Specifies a date.-f Specifies the format for the date.-i Output the date represented by the specified number (inverse of -t).-o Specify a number-of-days difference.-t Output the date as a number for comparison purposes.Without arguments, DATEX prints the current date and time.
If you wanted the Year, month, and day that was 13 days ago, you could include the following in your batch script:
for /f "Tokens=1-3 Delims=/ " %%a in ('datex -o -13') do ( set yyyy=%%a set month=%%b set day=%%c)
If you ran this command on July 13, 2004, yyyy would be set to 2004, month would be set to 06, and day would be set to 30.
The -13 offset means negative 13. If you wanted tomorrows date, include the following line:
for /f "Tokens=1-3 Delims=/ " %%a in ('datex -o 1') do ( set yyyy=%%a set month=%%b set day=%%c)
NOTE: If you need the ability to calculate the number of days between two dates, use:
Call JSIDateM YY1 MM1 DD1 - YY2 MM2 DD2
which will set the NND numeric environment variable to the signed difference. To calculate the number of days till Christmas:
call UnivDatecall JSIDateM %YY% 12 25 - %YY% %MM% %DD%@echo The number of days until Christmas is: %NDD%.
If you run the above on July 13, 2004, the output would be:
The number of days until Christmas is: 165.
About the Author
You May Also Like