Sunday, February 5, 2012

Calculate days between two dates



function calculate() {        
 var value1 = document.getElementById('<%=txtSDate.ClientID%>').value.split("/"); 
var value2 = document.getElementById('<%=txtEDate.ClientID%>').value.split("/");            
var getDays= new Date(value1[2], value1[1] - 1, value1[0]) //Month is 0-11 in JavaScript
 today = new Date(value2[2], value2[1] - 1, value2[0])
  //Get 1 day in milliseconds
var one_day = 1000 * 60 * 60 * 24
//Calculate difference btw the two dates, and convert to days
document.getElementById('<%=
txtnoofdays.ClientID%>').value=(Math.ceil((today.getTime() - getDays.getTime()) / (one_day)) +
" days !");
}

<asp:TextBox ID="txtSDate" runat="server"   Enabled="false"></asp:TextBox>
<asp:TextBox ID="txtEDate" runat="server" onkeyup="calculate();"  Enabled="false"></asp:TextBox>
<asp:TextBox ID="txtnoofdays" runat="server" Enabled="false"></asp:TextBox>


No comments:

Post a Comment

Comments

Search

Custom Search
Protected by Copyscape Plagiarism Software