0

I'm writing a simple event php script as an exercise which utilizes the mysql database. I'm trying to list all future festivals by date however it is listing no festivals.

The $nowdate_? variables are today's day, month, and year.

SELECT   * 
FROM     Festivals
WHERE    startdate_y <= " . $nowdate_y . " 
AND      startdate_m >= " . $nowdate_m . "
AND      startdate_d > " . $nowdate_d . "
ORDER BY startdate_y asc,startdate_m asc,startdate_d asc 
LIMIT    0,15

Am I approaching this incorrectly in the query?

thanks in advance

4

1 回答 1

0

You can not compare the date in parts.

You need

WHERE DATE_FORMAT(
          STR_TO_DATE(
              CONCAT_WS('-', startdate_y, startdate_m, startdate_d),
              '%Y-%m-%d'),
          '%Y-%m-%d')
      > CURRENT_DATE

The above expression might need a bit of fixing depending on what is exactly in the date fields.

于 2013-03-29T23:09:51.463 回答