我想查找表中包含特定日期日期列的所有记录,此时我正在尝试此查询,
SELECT *
FROM Table_ABC
WHERE DateCreated CONTAINS 24/10/2012
但它不起作用
答案 0 :(得分:5)
如果DateCreated列是DATETIME类型,您应该尝试:
SELECT *
FROM Table_ABC
WHERE YEAR(DateCreated) = 2012
AND MONTH(DateCreated) = 10
AND DAY(DateCreated) = 24
或只是
SELECT *
FROM Table_ABC
WHERE DATE(DateCreated) = "2012-10-24"
答案 1 :(得分:2)
尝试:
Select * from Table_ABC where DateCreated between '24/10/2012 HH:MM:SS' and '24/10/2012 HH:MM:SS'
将小时数和秒数更改为您想要的时间,通常是24小时。
答案 2 :(得分:0)
我会推荐以下声明:
SELECT *
FROM Table_ABC
WHERE CONVERT(DATE, DateCreated) = '2012-10-24'
CONVERT参考: https://docs.microsoft.com/sql/t-sql/functions/cast-and-convert-transact-sql