Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select from a DATETIME column using only a date?

I have a DATETIME column on my table which stores when a record was created. I want to select only the records created on a particular date. If I try:

SELECT * 
FROM myTable
WHERE postedOn =  '2012-06-06'

It returns no rows even though there are many rows in the table with the postedOn set as 2012-06-06 21:42:02, 2012-06-06 07:55:17 , and so forth.

Any ideas?

like image 288
Ali Avatar asked Dec 09 '22 23:12

Ali


1 Answers

Use the DATE scalar:

SELECT * 
FROM myTable
WHERE date(postedOn) =  '2012-06-06'
like image 163
Mark Wilkins Avatar answered Dec 29 '22 20:12

Mark Wilkins