sql 时间差

  select * from Tickets   
  where  
  (
  case when UnloadTime is null
  then datediff(hh,LoadTime,getdate())
  else datediff(hh,LoadTime,UnloadTime)
  end)>=48

这种方式是可以的

Linq时间差:

 //linq = linq.Where(x => System.Data.Entity.Core.Objects.EntityFunctions.DiffMilliseconds(x.LoadTime, x.UnloadTime)>48);
                    linq = linq.Where(x => System.Data.Entity.DbFunctions.DiffHours(x.LoadTime, x.UnloadTime) >= 48);

上面一种就很旧版本,下面是新的版本

sql时间方法应用

获取某日期的当天开始时间:

declare @Now datetime='2017-11-29 15:49:00';
--获取@Now日期的开始时间,例如-2017-11-29 00:00:00.000
declare @MinTodayTime datetime=convert(datetime,convert(varchar(10),@Now,120));
select @MinTodayTime;
 

datediff:

SELECT datediff( day,'1999/07/19 23:00','1999/07/20 01:59' )
原文地址:https://www.cnblogs.com/hongdada/p/6146050.html