The following j-script below calculates term in years, months and days. However, it is not working when there are leap years within the term. Here is an example of the behavior in the system with the script enabled. Clearly this is a 6 year lease, not a “5 Years, 11 Months, 28 Days” term:.
How I can I add leap year in following code.
here code I am using
/* Function calculates difference between Commencement and Expiry date and displays in the format 'X Yrs, Y Mos, Z Days' */
DateDifference = function(commence, expiry)
if(commence == null || expiry == null)
return '0 Yrs 0 Mos 0 Days';
// Difference between 2 dates
var diffDate = expiry - commence;
var years = diffDate/31536000000;
var months = (diffDate % 31536000000)/2628000000;
var days = ((diffDate % 31536000000) % 2628000000)/86400000;
// Result string
var result = Math.floor(years) + " Yrs, " + Math.floor(months) + " Mos, " + Math.floor(days) + " Days";
Please check the screen shot for more info