I want to get the number of years and months using Javascript, but I am not able to get to get them:
var date=new Date("2018-09-02")
document.body.innerHTML=calculateAge(date) //should print 1.1 year(s)
function calculateAge(date) {
var ageDifMs = Date.now() - date;
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
I have researched a lot, but I wasn't able to find the right approach to print the difference in yy.mm
format which is indicating year and months.