Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WildCard for dateTime column in SQL query

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

like image 521
Mathematics Avatar asked Apr 17 '26 23:04

Mathematics


2 Answers

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"
like image 197
fracz Avatar answered Apr 21 '26 01:04

fracz


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.

like image 29
sjramsay Avatar answered Apr 21 '26 02:04

sjramsay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!