Select mySQL based only on month and year

DiegoP. picture DiegoP. · Feb 2, 2012 · Viewed 246.9k times · Source

I have a column in my mySQL DB that has some rows. One of this row is a DATE, like this: 2012-02-01

What I want to achieve is to do a SELECT with PHP based only on the year and month.

The logic of the SELECT will be the following:

$q="SELECT * FROM projects WHERE Date="SELECT HERE THE SPECIFIC YEAR AND MONTH"";

The specific month and year will be be passed from a $_POST variable, like this $_POST['period']="2012-02";

How can I do it?

Answer

Rick Kuipers picture Rick Kuipers · Feb 2, 2012
SELECT * FROM projects WHERE YEAR(Date) = 2011 AND MONTH(Date) = 5