本文介绍了如何计算没有一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!<tr><td valign="top" align="center">Training Date</td><td valign="top" align="left"><b>FROM</b> <asp:TextBox ID="txtDatefrom" runat="server" Width="240px" Height="30px"></asp:TextBox> <asp:Image ID="imgDatefrom" runat="server" ImageUrl="~/img/cal.gif" /> <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" TargetControlID="txtDatefrom" WatermarkText="1/1/2001"> </cc1:TextBoxWatermarkExtender> <cc1:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="imgDatefrom" TargetControlID="txtDatefrom" PopupPosition="TopRight" > </cc1:CalendarExtender></td><td valign="top" colspan="5" align="left"><b>TO</b> <asp:TextBox ID="txtDateto" runat="server" Width="300px" Height="30px"></asp:TextBox> <asp:Image ID="imgDateto" runat="server" ImageUrl="~/img/cal.gif" /> <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" runat="server" TargetControlID="txtDateto" WatermarkText="1/1/2001"> </cc1:TextBoxWatermarkExtender> <cc1:CalendarExtender ID="CalendarExtender2" runat="server" PopupButtonID="imgDateto" TargetControlID="txtDateto" PopupPosition="TopRight" > </cc1:CalendarExtender></td></tr><tr><td valign="top" align="center">No of Days(in numeric)</td><td valign="top" colspan="6" align="left"> <asp:TextBox ID="txtNoofdays" runat="server" Width="300px" Height="30px"></asp:TextBox></tr> in .CSin .CSpublic void InsertData() { string fromdate = System.DateTime.Now.ToString(); txtDatefrom.Text = Convert.ToDateTime(fromdate).ToString(); string todate = System.DateTime.Now.ToString(); txtDateto.Text = Convert.ToDateTime(todate).ToString(); string noofday =da = new SqlDataAdapter("Insert Into Feedback_training(From_training_date,To_training_date,Noof_days)values('" + txtDatefrom.Text + "','" + txtDateto.Text + "','"+noofday+"')", con); ds = new DataSet(); da.Fill(ds); 注意: - 我已经插入了fromdate和todate的值。我想要天数记录并存储在数据库中(如何从日期和todate中区分b / w)我已经在数据库中有一天没有天数,数据类型是int推荐答案DateTime dtFrom = DateTime.Now.AddDays(-5); DateTime dtTo = DateTime.Now; int NoOfDays = (dtTo - dtFrom).Days; TotalDays 将为您提供 double 包括时间TotalDays will gives you result in double including the time hoursDateTime dtFrom = DateTime.Now.AddDays(-5); DateTime dtTo = DateTime.Now.AddHours(6); double NoOfDays = (dtTo - dtFrom).TotalDays;int noOfDays = (todate - fromdate).Days; 这篇关于如何计算没有一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!