Assuming
data
is in the format
DATE
,
DATETIME
or
TIMESTAMP
,
$condicaoData
must be in
YYYY-MM-DD
format.
You can do two things: provide the date in the format received and use the function DATE_FORMAT
of MySQL or transform the date received in the format required by MySQL.
To use the DATE_FORMAT
function:
$sql = "
SELECT *
FROM noticias
WHERE data >= DATE_FORMAT('$condicaoData', '%d/%m/%Y')
ORDER BY id DESC";
To transform the received format into MySQL format:
// caso você possa gerar a data no formato Y-m-d
$condicaoData = date('Y-m-d', strtotime("-3 days"));
// ou caso você já tenha a data no formato d/m/Y
$condicaoData = preg_replace(
'/^(\d+)\/(\d+)\/(\d+)$/',
'$3-$2-$1',
date('d/m/Y', $condicaoData));
And then SQL would be:
$sql = "
SELECT *
FROM noticias
WHERE data >= '$condicaoData'
ORDER BY id DESC";
Another tip: Consider using Prepared Statements , which is the most secure option to protect your database against SQL injection-type attacks. So the query is cached in your database and the only things that change are the parameters - in this case, the dates of your query.