我们如何通过使用datetimepicker获得日期差异? [英] How can we get date difference with the use of datetimepicker?
本文介绍了我们如何通过使用datetimepicker获得日期差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
System.DateTime f = dateTimePicker1.Value;
System.DateTime g = dateTimePicker2.Value;
System.TimeSpan diff = f.Subtract(g);
textBox1.Text = Convert.ToString(diff);
我不能得到日期差异。
当我选择12/05/2013和25/06/2013时,我得到了差异00.00.0000。
如何找到日期差异?
I can''t get the date difference.
When I select 12/05/2013 and 25/06/2013, I get the difference as 00.00.0000.
How can I find the date difference?
推荐答案
你要从f中减去g。没关系。但事先,你将dateTimePicker1.Value分配给两个变量。
你应该将另一个DateTimePicker'的值分配给变量g或f中的一个。
You''re subtracting g from f. That''s fine. But beforehand, you assign dateTimePicker1.Value to both variables.
You should assign another DateTimePicker''s Value to one of the variables g or f.
试试这个
try this
System.DateTime todt = dateTimePickerTodate.Value;
System.DateTime fromdt = dateTimePickerFromdate.Value;
System.TimeSpan diff = todt.Subtract(fromdt);//generally we substract smallar date from bigger else it will return Totaldays in negative sign
textBox1.Text = Convert.ToString(diff.TotalDays);
< br $>
快乐编码!
:)
Happy Coding!
:)
这篇关于我们如何通过使用datetimepicker获得日期差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文