function getAge(fromdate, todate) { var currentDate = new Date(); if (todate) todate = new Date(todate); else todate = new Date(); if (fromdate) fromdate = new Date(fromdate); else fromdate = new Date(); if (fromdate.valueOf() > todate.valueOf()) { // if future date } else { var age = [], fromdate = new Date(fromdate), y = [todate.getFullYear(), fromdate.getFullYear()], ydiff = y[0] - y[1], m = [todate.getMonth(), fromdate.getMonth()], mdiff = m[0] - m[1], d = [todate.getDate(), fromdate.getDate()], ddiff = d[0] - d[1]; ...