Wednesday, 21 January 2015

How to do the date difference using javascript?

I have two textboxes i want to calculate the year difference between two Dates.

function CalcalationofDATE()
{
//getting the dates from textboxes
var Date1 = document.getElementById('txtDate.CLIENTID').value;
var Date2 = document.getElementById(' txtDate1.CLIENTID').value;

//if the dates are not there empty asign value
if (Date1 == "" || Date2 == "")
{
document.getElementById('txtdateDiff').innerHTML = "";
}
else
{
var dt1 = new Date(Date1);
var dt2 = new Date(Date12);
var dtVal = dt1.getFullYear() - dt2.getFullYear();
document.getElementById('txtdatediff').innerHTML = dtVal;

}
}

No comments:

Post a Comment