php – How to not display records from past dates

Question:

I made an agenda and I need that events that have already passed don't appear anymore, the dates have 3 fields DAY/MONTH/YEAR, I'm using concat and date to join and format the dates, so the current query looks like this:

$query = mysql_query("SELECT * FROM `tabela1` WHERE `evento` LIKE '%$busca%' ORDER BY date(concat(ano,'-', mes,'-',dia)) ASC") or die(mysql_error());

Answer:

SELECT *
FROM `tabela1`
WHERE `evento` LIKE '%$busca%'
AND `nomeDoCampoData` > '2014-04-10'
ORDER BY date(concat(ano,'-', mes,'-',dia)) ASC

If you want to pick up between a period use between

SELECT *
FROM `tabela1` 
WHERE `evento` LIKE '%$busca%'
AND `nomeDoCampoData` BETWEEN '2014-04-10' AND '2014-04-13'
ORDER BY `nomeDoCampoData`

Tip don't use a field for each one: date, month, year… Use only one field of type DATE

Scroll to Top