数据库里面的字段:
StartDate EndDate
2007-5-3 14:00:00 2007-6-3 15:00:00
想在web上放个Table或者是TextBox 只要点下Button就能计算出它们的总时间.请教?
------解决方案--------------------------------------------------------
先从数据库中读取时间.然后用程序计算.或者直接用sql计算select datediff(D, '2007-5-3 14:00:00 ', '2007-6-3 15:00:00 ')
------解决方案--------------------------------------------------------
膜拜胸高手啊
------解决方案--------------------------------------------------------
DateTime dt1 = DateTime.Parse( "2007-5-3 14:00:00 ");
DateTime dt2 = DateTime.Parse( "2007-6-3 15:00:00 ");
DateSpan ds = dt2 - dt1;
double days = ds.TotalDays;
//...
------解决方案--------------------------------------------------------
private string DateDiff(DateTime DateTime1, DateTime DateTime2)
{
string dateDiff = null;
try
{
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
dateDiff = ts.Days.ToString() + "天 "
+ ts.Hours.ToString() + "小時 ";
//+ ts.Minutes.ToString() + "分钟 "
//+ ts.Seconds.ToString() + "秒 ";
}
catch
{
}
return dateDiff;
}
------解决方案--------------------------------------------------------
用TIMESPN减一个就知道了