Welcome!

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

SignUp Now!

How to? date1 - date2 = number of days

Apr
1,822
17
How would it be best be done?

dates are in the form of m/d e.g. 9/8 for September 8th.

some are also m/d/y if it's next year.

thanks in advance.
 
Here's a start. But the date formats will need to be standardized. @MAKEAGE has a second parameter that lets you specify one of seven date formats
Code:
v:\> function days `%@eval[(%@makeage[%2]-%@makeage[%1]) / (10000000*60*60*24)]`

v:\> echo %@days[2016-06-16,2016-08-11]
56

v:\> echo %@days[2016-06-16,2017-08-11]
421
 
My first one was faulty. This is better and lets you use mm/dd/yy.
Code:
v:\> function days `%@eval[(%@makeage[%2,,1]-%@makeage[%1,,1]) / (10000000*60*60*24)]`

v:\> echo %@days[8/11/16,8/11/17]
365
 
The VBScript DateDiff function is a solution that can be used with TCC;

Code:
@setlocal
@echo off
setdos /X-5
echo dtm1="01-Jan-16" > %@path[%_batchname]\dd.vbs
echo dtm2="%_Day-%_Monthf-%_Year" >> %@path[%_batchname]\dd.vbs
echo WScript.Echo "Difference between " & dtm1 & " and " & dtm2 >> %@path[%_batchname]\dd.vbs
echo intMonthsDifferent=DateDiff("d", dtm1, dtm2) >> %@path[%_batchname]\dd.vbs
echo WScript.Echo intMonthsDifferent >> %@path[%_batchname]\dd.vbs
setdos /X0
iff exist %@path[%_batchname]\dd.vbs then
  cscript //nologo %@path[%_batchname]\dd.vbs
  del /q %@path[%_batchname]\dd.vbs
else
  echo dd.btm - Error in creating %@path[%_batchname]\dd.vbs
endiff
endlocal

More info on the VBScript DateDiff function->: [title]

Joe
 
My first one was faulty. This is better and lets you use mm/dd/yy.
Code:
v:\> function days `%@eval[(%@makeage[%2,,1]-%@makeage[%1,,1]) / (10000000*60*60*24)]`

v:\> echo %@days[8/11/16,8/11/17]
365

The *60*60*24 is obvious but why the 10000000 ?
 
Here's a start. But the date formats will need to be standardized. @MAKEAGE has a second parameter that lets you specify one of seven date formats
Code:
v:\> function days `%@eval[(%@makeage[%2]-%@makeage[%1]) / (10000000*60*60*24)]`

v:\> echo %@days[2016-06-16,2016-08-11]
56

v:\> echo %@days[2016-06-16,2017-08-11]
421

I like the function days above. How about similar functions xxx for function name

@xxx[date,days] = returns date that is + or - days from specified date
 
Back
Top
[FOX] Ultimate Translator
Translate