javascript - how to calculate the duration of year when user entered the date in textbox -
how display duration?when dated entered in textbox,in next field total number of years(duration). example: if user entered 09/11/2015.it should displayed 0.5 value,by comparing today's date. `now use script script
function cal() { 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; } } } }
`
function aa(){ var oneday = 24*60*60*1000; // hours*minutes*seconds*milliseconds var firstdate = new date(2016,04,12); var seconddate = new date(2016,04,25); var diffdays = math.round(math.abs((firstdate.gettime() - seconddate.gettime())/(oneday))); alert(diffdays+" day(s)"); //document.getelementbyid('test').innerhtml=diffdays; }
<button onclick="aa()"> click </button>
Comments
Post a Comment