How can I show the duration in years? After a date is entered into a text box, the total number of years (duration) should be displayed in the next field. For example, if a user enters 09/11/2015, it should display as 0.5 as the value by comparing it to today's date. I am currently using the following script:
function calculateDuration()
{
obj = document.getElementById("Date");
if (obj != null) {
if (obj.value != "") {
var year = obj.value.split("/")[2];
var today = new Date();
if (year > today.getFullYear()) {
alert("Invalid Year");
document.getElementById("Date").value = "";
document.getElementById("year").value = "";
}
else {
document .getElementById("year").value = today.getFullYear() - year;
} }
}
}
`