If you want to retrieve rows with the correct month, regardless of year, then you probably want the MONTH() function. It returns the month part of a date as an integer from 1 to 12, so you could do

  SELECT id, datecol, text FROM table
  WHERE MONTH(datecol) = $mySelectedMonth;

Note, however, that passing datecol through a function like this renders any index on datecol useless for the purposes of the WHERE clause.

If you want rows from the given month of the given year, use BETWEEN. For example, if you want rows from February of 2004, you would

  SELECT id, datecol, text FROM table
  WHERE datecol BETWEEN '2004-02-01' AND '2004-02-29';

In this case, an index on datecol could be used.

See <http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html>.

Michael

H Bartel wrote:

Hi,

I am trying to start using the mySQL Date functions instead of the unix
timestamp from PHP. I have read the man page several times now, but
still haven't come up with a solution for this simple query:

SELECT id, datecol, text FROM table WHERE month-in-date-col =
$mySelectedMonth;

This shouldn't be too hard, I guess, but it seems I'm missing something
here? Any help greatly appreciated.

Regards,
Holger



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to