如何用c#计算asp

如何用c#计算asp

本文介绍了如何用c#计算asp.net中两个日历之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>

推荐答案


DateTime startDate = DateTime.Parse(txtDatefrom.Text);
DateTime endDate = DateTime.Parse(txtDateTo.Text);
TimeSpan diff = endDate - startDate;
double days = diff.TotalDays;


这篇关于如何用c#计算asp.net中两个日历之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 20:17