2

I want to look for all records within a table that has date column for a specific date, at the moment I am trying this query,

SELECT     *
FROM      Table_ABC
WHERE     DateCreated CONTAINS 24/10/2012

But its not working

4

4 回答 4

7

If the DateCreated column is a DATETIME type, you should try:

SELECT     *
FROM      Table_ABC
WHERE     YEAR(DateCreated) = 2012
AND       MONTH(DateCreated) = 10
AND       DAY(DateCreated) = 24

or simply

SELECT     *
FROM      Table_ABC
WHERE     DATE(DateCreated) = "2012-10-24"
于 2012-10-24T11:20:32.777 回答
2

Try:

Select * from Table_ABC where DateCreated between '24/10/2012 HH:MM:SS' and '24/10/2012 HH:MM:SS'

Changes hours minutes and seconds to be what you want it to be and it's usually in 24 hour time.

于 2012-10-24T11:22:11.267 回答
1

I would recommend the following statement:

SELECT    *
FROM      Table_ABC
WHERE     CONVERT(DATE, DateCreated) = '2012-10-24'

Reference for CONVERT: https://docs.microsoft.com/sql/t-sql/functions/cast-and-convert-transact-sql

于 2017-05-24T12:06:30.193 回答
0

In case it's helpful, this adds a wildcard:

SELECT    *
FROM      Table_ABC
WHERE     CONVERT(DATE, DateCreated) LIKE '%2012-10-24%'
于 2021-08-20T15:50:28.237 回答