本文介绍了如何在两个DateTimePickers之间进行操作以获取天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在两个DateTimePickers之间进行了一次操作,以获取JUST DAYS的天数(没有几个月没有时间),但是我遇到了一些麻烦.
我执行了这段代码,但是它只在year(2011)期间有效,当日期从流动的year(2012)开始时,
例如:2013年1月1日-2012年12月31日= -365
i did an operation between two DateTimePickers to get number of days JUST DAYS (no months no time), but i face some troubles.
i did this code, it works but just through the period of year(2011), when the date begin in flowing year(2012) ,
for example : 01/01/2013 - 31/12/2012 = -365
TbnbJourLocation.Text = (DtpDateRetour.Value.DayOfYear - DtpDateLocation.Value.DayOfYear ).ToString();
我试过了,但这不仅给了我几天的时间,而且还给了我几天,时间,一个月...
and i tried this but it gives me not just number of days, but it''s gives me days , time, month...
TbnbJourLocation.Text = (DtpDateRetour.Value - DtpDateLocation.Value ).ToString();
所以请帮助我,它非常重要.
so please help me it''s very important
推荐答案
Timespan result = DtpDateRetour.Value - DtpDateLocation.Value;
TbnbJourLocation.Text = Convert.ToInt32( result.TotalDays + 0.5 ).ToString();
TimeSpan dateDifference = new TimeSpan();
DateTime beginDate = DtpDateRetour.SelectedDate;
DateTime endDate = DtpDateLocation.SelectedDate;
dateDifference = beginDate.Subtract(endDate);
祝你好运,
OI
Good luck,
OI
TimeSpan ts = DtpDateRetour.Value.Subtract(DtpDateLocation.Value);
TbnbJourLocation.Text = ts.Days.ToString();
这篇关于如何在两个DateTimePickers之间进行操作以获取天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!