如何从sql中的表中检索下一个5小时的数据

时间:2013-07-22 07:35:56

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

SELECT *
FROM TABLENAME
WHERE 
       text_date < GETDATE()
     AND 
       text_date < DATEADD(MINUTE, 300, GETDATE())

这有什么问题吗?

2 个答案:

答案 0 :(得分:3)

 DECLARE @AddTime DATETIME
  SELECT @AddTime = GETDATE();

 SELECT *
  FROM TABLENAME
 WHERE text_date BETWEEN @AddTime AND DATEADD(HOUR, 5, @AddTime );

Reference

答案 1 :(得分:2)

试试这个 -

DECLARE @Data DATETIME
SELECT @Data = GETDATE()

SELECT *
FROM TABLENAME
WHERE text_date BETWEEN @Data AND DATEADD(MINUTE, 300, @Data)