SQL 服务器 : How to select rows that were inserted on the same day?

标签 sql sql-server datetime between

我有一个循环,它遍历一些条目。在循环中,我得到了创建日期,我需要查找是否有在同一天插入的条目。例如,如果 creation date = 2011-08-31 21:19:14.345,我需要选择创建日期在 2011-08-31 00:00:00.000 之间的所有行2011-08-31 23:59:59.999

如何使用 SQL 执行此操作?

最佳答案

为了捕捉当天的所有时间,请执行以下操作:

SELECT * FROM MyTable
WHERE DateCreated >= @TheDate AND DateCreated < DATEADD(day, 1, @TheDate)

其中 @TheDate 必须是没有时间的纯日期。即使 DateCreated 的时间部分非常接近午夜,它也能正常工作。

关于SQL 服务器 : How to select rows that were inserted on the same day?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8404842/

相关文章:

mysql - 大数据库上的快速mysql随机加权选择

sql-server - 根据也正在更新的另一列的值更新列

sql - 从另一个表的列中选择记录等项目

sql-server - SQL Server 2008 R2 : Concatenate alias name with column value

java - SimpleDateFormat setTimeZone 不工作

php - 从日期中恰好删除一个月

python - 使用Python sqlite3,我应该在任何SQL操作和commit()之后使用sleep()吗?

sql - Amazon Redshift 错误 - 错误 : 0A000: Specified types or functions (one per INFO message) not supported on Redshift tables

SQL连接技术

javascript - 想要从日期 javascript 中减去 5.30 小时