Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<pre lang="HTML"></pre>
<table width="100%">
 <tr>
     <td valign="top" align="center"><strong>Training Date</strong></td>
     <td valign="top" align="left"><b>FROM</b><br />
         <asp:TextBox ID="txtDatefrom" runat="server"></asp:TextBox>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator4" SetFocusOnError="true" runat="server" ErrorMessage="Field Can't Empty" ControlToValidate="txtDatefrom">
         </asp:RequiredFieldValidator><br />
         <asp:Image ID="imgDatefrom" runat="server" ImageUrl="~/img/cal.gif" />
         <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" TargetControlID="txtDatefrom" WatermarkText="00/0/0000"></cc1:TextBoxWatermarkExtender>
        <cc1:CalendarExtender ID="CalendarExtender1" Format="dd/MM/yyyy" runat="server"
         PopupButtonID="imgDatefrom" TargetControlID="txtDatefrom" PopupPosition="TopRight">
        </cc1:CalendarExtender>
</td>

<td valign="top" colspan="4" align="left"><b>TO</b><br />
 <asp:TextBox ID="txtDateto" runat="server"></asp:TextBox>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" SetFocusOnError="true" ErrorMessage="Field Can't Empty" ControlToValidate="txtDateto" ForeColor="#990000"></asp:RequiredFieldValidator><br />
  <asp:Image ID="imgDateto" runat="server" ImageUrl="~/img/cal.gif" />
  <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" runat="server" TargetControlID="txtDateto" WatermarkText="00/0/0000">
  </cc1:TextBoxWatermarkExtender>
 <cc1:CalendarExtender ID="CalendarExtender2" Format="dd/MM/yyyy" runat="server"
     PopupButtonID="imgDateto" TargetControlID="txtDateto" PopupPosition="TopRight">
 </cc1:CalendarExtender>
</td>
</tr>
<tr>
     <td valign="top" align="center"><strong>No of Days(in numeric)</strong></td>
     <td valign="top" colspan="3" align="left">
     <asp:TextBox ID="txtNoofdays" runat="server"></asp:TextBox>
     </td>

</tr>
</table>
<b>NOTE:-How to calculate no of days between two calender in asp.net with c# </b>
Posted
Updated 23-Feb-14 20:42pm
v2
Comments
Ramug10 24-Feb-14 2:45am    
Are you want to calculate no of days between txtDatefrom and txtDateto?
Sergey Alexandrovich Kryukov 24-Feb-14 2:50am    
What is "calender"? :-)
—SA

Easy: take the two TextBox values, convert them to DateTime objects, and subtract one from the other:
C#
DateTime startDate = DateTime.Parse(txtDatefrom.Text);
DateTime endDate = DateTime.Parse(txtDateTo.Text);
TimeSpan diff = endDate - startDate;
double days = diff.TotalDays;
 
Share this answer
 
Comments
ashishmagneti 24-Feb-14 5:14am    
i used this code but its not working
OriginalGriff 24-Feb-14 5:23am    
"It's not working" doesn't tell us much - what is it doing that you didn't expect, or not doing that you did?
Remember, we can't see your screen, or access your HDD, or read your mind - so tell us what is going on, tell us what the inputs are, etc.!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900