如何从两个日期的文本框中计算天数? [英] How to calculate days from two date textbox?

查看:181
本文介绍了如何从两个日期的文本框中计算天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框,通过使用快速应用程序开发datepicker文本框可以在上面输入两个日期.我还有一个文本框,我想在上面显示这两个文本框日期的持续时间.
我想计算到目前为止的总天数.谁能为我提供解决方案?

I have two text box on which I give two date input by using rapid application development datepicker textbox. I have another text box on which I wanna show the duration of those two text box date.
I want to calculate total days of those to date. Can anyone please provide me a solution?

推荐答案

更好的解决方案:
Better solution:
TimeSpan ts = secondDate.Value - firstDate.Value;
myTextBox.Text = ts.Days.ToString();


如果仅使用DateTime.Day,则如果月份发生变化等,您将遇到问题.


If you just use DateTime.Day, then you will get problems if the month changes, etc.


尝试 x = DateTimePicker1.Value.Day - DateTimePicker2.Value.Day.


更好的解决方案是:
两天均为日期时间格式

System.TimeSpan span = ToDate-DateFrom;
int days =(int)span.TotalDays;
Better Solution is :
Both Days are in Date time Format

System.TimeSpan span = ToDate - DateFrom;
int days = (int)span.TotalDays;


这篇关于如何从两个日期的文本框中计算天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆