-
1. Re: Calculating date fields
GKaiseril Jun 1, 2012 9:04 AM (in response to Smitch1581)Yes, you use the JavaScript date object to extract the full year and month from the entry fields, create a lowest common denominator for the month and year, and do the math.
The custom calculation event for the number of months:
// clear the result value
event.value = "";
// get field values
var sStart = this.getField("Date1").value;
var sEnd = this.getField("Date2").value;
// process only if we have data
if(sStart != "" && sEnd != "") {
// convert date strings to date objects
var oStart = util.scand("mmm yyyy", sStart);
var oEnd = util.scand("mmm yyyy", sEnd);
// get the start date full year and month
var nStartFullYear = oStart.getFullYear();
var nStartMonth = oStart.getMonth();
// convert start data to months
var nStartMonths = (nStartFullYear * 12) + nStartMonth;
// get the end date full year and month
var nEndFullYear = oEnd.getFullYear();
var nEndMonth = oEnd.getMonth();
// convert end data to months
var nEndMonths = (nEndFullYear * 12) + nEndMonth;
// do the math
event.value = nEndMonths - nStartMonths;
} // end have data
You will have to adjust the names for the start and end dates.
-
2. Re: Calculating date fields
Smitch1581 Jun 1, 2012 11:28 AM (in response to GKaiseril)Genius! Thank you very much, that works a treat.
Thank you


