This javascript can get the total of the "DAYS" value
=============================================================
var strStart = this.getField("DateStart").value;
var strEnd = this.getField("DateEnd").value;
if(strStart.length && strEnd.length)
{
var dateStart = util.scand("mmm d, yyyy",strStart);
var dateEnd = util.scand("mmm d, yyyy",strEnd);
var diff = dateEnd.getTime() - dateStart.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
event.value = days;
}
else
event.value = 0;
=============================================================
How to change can get the total of the "MONTHS" value??
for example,
DateStart: 01/01/2000
DateEnd: 01/02/2001
result is 13
Plase help and thanks!!
It is not consistent from month to month, so you can not use converting the dates to a time value and then compute.
With paper and pencil, one can convert the years to months and add that value to the months for each date to get the total month for each date. Then if one subtracts the total months for each data, one would have the number of complete months between the dates. Add 1 to include the ending month.
function Date2Months(cFormat, sDate) {
var nMonths = 0;
// convert date string to date object
var oDate = util.scand(cFormat, sDate.toString();
// get the years
var nYears = oDate.getFullYear();
// get then months
nMonths = oDate.getMonth();
// add the years in months and return the value
return nMonths + (12 * nYeaars);
} // end Date2Months
var strStart = this.getField("DateStart").valueAsString;
var strEnd = this.getField("DateEnd").valueAsString;
if(strStart.length && strEnd.length)
{
// get number of months for start date
var nStart = Date2Months("mmm dd, yyyy", strStart);
// get number or months for end date
var nEnd = Date2Months("mmm dd, yyyy", strEnd);
// compute difference
event.value = nEnd - nStart;
}
else
event.value = 0;
George Kaiser