1

我正在尝试运行一个 T-SQL 查询,该查询将返回包含00:00:00任何给定日期之间的时间戳的所有行。

我使用了以下代码,但这仅返回过去 24 小时内的项目:

SELECT *
FROM table
WHERE timestamp_closed =  DATE(GETDATE()-1);
4

5 回答 5

2
SELECT *
FROM table
WHERE timestamp_closed BETWEEN CAST(GETDATE() AS DATE) AND GETDATE()
于 2013-11-08T15:29:33.623 回答
2

这里有行数:

SELECT COUNT(*)
FROM *yourtable*
WHERE timestamp_closed BETWEEN CAST(GETDATE() AS DATE) AND GETDATE()
于 2013-11-08T15:31:39.870 回答
1

您可以为“今天 00:00:00”构建日期值,然后不时执行

WHERE timestamp_closed >= "Today at 00:00:00" and timestamp_closed<=GETDATE()
于 2013-11-08T15:30:35.523 回答
0

您可能可以将其包装在一个函数中。

select * 
from table
where datepart(hh,timestamp_closed)*100 + datepart(mi,timestampclosed) < 
    datepart(hh,getdate())*100 + datepart(mi,getdate())
于 2013-11-08T15:43:58.843 回答
0
SELECT *
FROM table
WHERE (timestamp_closed >  CAST(@specificDate AS DATE)
AND timestamp_closed <= GETDATE())
于 2013-11-08T15:34:06.023 回答