/// <summary> /// 计算两个日期的时间间隔 /// </summary> /// <param name="DateTime1">第一个日期和时间</param> /// <param name="DateTime2">第二个日期和时间</param> /// <returns></returns> private string DateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = null; 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()+"秒"; return dateDiff; }
//比较时间大小
string st1="12:13";
string st2="14:14";
DateTime dt1=Convert.ToDateTime(st1);
DateTime dt2=Convert.ToDateTime(st2);
DateTime dt3=DateTime.Now;
if(DateTime.Compare(dt1,dt2)>0)
msg.Text=st1+">"+st2;
else
msg.Text=st1+"<"+st2;
--如果
--RemindTime='' RemindFormata为空
--RemindTime大于现在,那么获取其时间差 。。天。。小时。。分钟
--RemindTime小于现在,那么截取获取其日期 例:08-31 select case when a.RemindTime='' then '无' when a.RemindTime>GetDATE() then cast(floor(datediff(minute,GETDATE(),a.RemindTime) / 1440) as varchar)+'天'+cast(floor((datediff(minute,GETDATE(),a.RemindTime) % 1440)/60) as varchar)+'小时'+ cast(((datediff(minute,GETDATE(),a.RemindTime))-(floor(datediff(minute,GETDATE(),a.RemindTime) / 1440) *1440)-(floor((datediff(minute,GETDATE(),a.RemindTime) % 1440)/60)*60)) as varchar)+'分' when a.RemindTime<GetDATE() then SUBSTRING(CONVERT(varchar(10), a.RemindTime, 23),6,10) end as RemindFormata from [dbo].[收文] as a order by ID DESC