找出特定时间参数内的两个日期字段之间的差异

时间:2011-04-28 21:24:51

标签: sql sql-server sql-server-2005 sql-server-2008

我尝试了几种方法,但这是我的SQL伪代码:

select count(*) as counter 
where startDate and endDate is 30 minutes and archived = 1.  

mssql字段的数据类型为datetime

我的另一个想法是将其提交到select语句并向dateadd添加datdiff,但我不确定如何解释这两个单独的字段( startDateEndDate)...

我希望有人可以理顺我。

2 个答案:

答案 0 :(得分:4)

SELECT  COUNT(*)
FROM    mytable
WHERE   endDate <= DATEADD(minute, 30, startDate)
        AND archieved = 1

答案 1 :(得分:2)

SELECT COUNT(*)
FROM YourTable
WHERE DATEDIFF(MINUTE,StartDate,EndDate) <= 30
AND Archived = 1