How to select only date from a DATETIME field in MySQL?

DiegoP. picture DiegoP. · Jan 27, 2012 · Viewed 264.9k times · Source

I have a table in the MySQL database that is set up with DATETIME. I need to SELECT in this table only by DATE and excluding the time.

How do I SELECT in this table by only date and bypassing the time, even if that specific column is set to DATETIME?


Example

Now it is: 2012-01-23 09:24:41

I need to do a SELECT only for this: 2012-01-23

Answer

Balaswamy Vaddeman picture Balaswamy Vaddeman · Jan 27, 2012

SELECT DATE(ColumnName) FROM tablename;

More on MySQL DATE() function.