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' )

sql 时间差的更多相关文章

  1. SQL 时间差函数

    SELECT DateDiff(DAY,T.ActualEndDate,GetDate())  FROM JCW_CheckTask T WHERE T.status = 2

  2. SQL求解两个时间差

    sql 求解两个时间差 SELECTDATEDIFF( Second, '2009-8-25 12:15:12', '2009-9-1 7:18:20') --返回相差秒数 SELECTDATEDIF ...

  3. sql查询两条记录的时间差

    今天突然想到了一个需求,即在一张带有id和time字段的表中,查询相邻时间的时间差. 表的记录如下: 表名为wangxin id是一个不重复的字符串,time是一个时间戳. 现在的需求如下: 比如id ...

  4. Sql Server中使用存储过程来实现一些时间差的改变

    Sql Server中的时间差是使用DATEDIFF来是现的 语法如下:DATEDIFF(要显示时间格式,开始时间,结束时间) 比如:DATEDIFF(minute,'2019-2-28 8:30', ...

  5. SQL计算时间差并排除周末

    SQL计算时间差并排除周末 CREATE FUNCTION DI_FN_GET_WorkDay (@begin DATETIME , @end DATETIME ) RETURNS int BEGIN ...

  6. 断今天日期和指定日期相等和两者的时间差为两年的sql

    1.  ---判断今天日期和指定日期相等 update store  set Status =1 where CONVERT(varchar(12) ,opendate, 105 )= CONVERT ...

  7. 常用的获取时间差的sql语句

    "select count(*) from [注册] where datediff(day,time,getdate())<1";//获取当天注册人员数 sql=" ...

  8. 求时间差的sql语句。 比如如下数据

    msisdn createtime closetime138 2011-5-17 15:30:00:000 2011-5-17 15:30:00:530138 2011-5-17 15:40:00:0 ...

  9. SQL 建表与查询 HTML计算时间差

    create database xue1 go --创建数据库 use xue1 go --引用数据库 create table xinxi ( code int, name ), xuehao ), ...

随机推荐

  1. Codeforces Testing Round #10 B. Balancer

    水题,只要遍历一遍,不够平均数的,从后面的借,比平均数多的,把多余的数添加到后面即可,注意数据范围 #include <iostream> #include <vector> ...

  2. IOS UI segmentedControl UISegmentedControl 常见属性和用法

    UISegmentedControl中一些常见的属性和用法 //设置以图案作为分段的显示,仅需要图案的轮廓,这样颜色为分段的背景颜色 //    NSArray *items = @[[UIImage ...

  3. Tomcat_启动多个tomcat时,会报StandardServer.await: Invalid command '' received错误

    解决方案如下:将tomcat下的server.xml文件中的端口有问题,修改规则按以下标准显示“http的端口修改为6000 to 6800之间,shutdown的端口修改为3000 to 3300之 ...

  4. linux下定时重启tomcat

    工具/原料 linux tomcat 方法/步骤 编写tomcat_shutdown.sh: #!/bin/sh export JAVA_HOME=/home/oracle/jdk1..0_67/ e ...

  5. About_AJAX

    Asynchronous JavaScript And XML (1)AJAX大多用于验证和分页: (2)首先要激活(对象): window.ActiveXObject(针对IE): window.X ...

  6. Android 图片三级缓存

    图片缓存的原理 实现图片缓存也不难,需要有相应的cache策略.这里采用 内存-文件-网络 三层cache机制,其中内存缓存包括强引用缓存和软引用缓存(SoftReference),其实网络不算cac ...

  7. 1071. Speech Patterns (25)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  8. 基于canvas的前端图片压缩

    /*common*/ /** * canvas图片压缩 * @param {[Object]} opt [配置参数] * @param {[Function]} cbk [回调函数] * @retur ...

  9. 【android】新手容易遇到的[error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.]Theme出错的问题

    一.概述 近期刚接手了一个项目,开发工具为eclipse,由于版本较低,且考虑到如果转android studio项目的话,会其他人的维护带来困难,所以想着还是维护项目原来的开发环境吧. 但是导入项目 ...

  10. Winform Combox DataSource 之不显示 displayemember 内容

    刚开始学习数据绑定的东西, private void Form1_Load(object sender, EventArgs e) { IList<TLayer> tt = new Lis ...