icecub
icecub

Reputation: 8783

MySQL select specific date from datetime

I'm trying to setup a mysql select query based on a given date in a datetime column. Something like:

SELECT DATE_FORMAT(colName, '%Y-%m-%d') WHERE..

But I'm unsure on how to do this correctly. I'm using php to do this.

Upvotes: 0

Views: 1058

Answers (2)

Elixir Techne
Elixir Techne

Reputation: 1856

Following example explain the query to select date between 01-Jan-2014 and 15-Jan-2014.

SELECT 
    DATE_FORMAT(colName, '%Y-%m-%d') AS colName
FROM 
    `my_table` 
WHERE 
    DATE_FORMAT(colName, '%Y-%m-%d') >= '2014-01-01' AND DATE_FORMAT(colName, '%Y-%m-%d') <= '2014-01-15'

Upvotes: 1

Leo
Leo

Reputation: 6580

To verify your query, use sqlfiddle and use a query without any table such as

SELECT DATE_FORMAT(now(), '%Y-%m-%d') from dual

Upvotes: 0

Related Questions