Question:
$result_usuario = "SELECT * FROM vendas WHERE DATE(date_created) = '$data' AND tipo_venda = '$tipo_vendas' AND tipo = '$tipo_pagamento' ORDER BY 'id'";
I have this query, but it doesn't work right because the input that fills the variable '$data' comes with the format '11/12/2018' and the format that counts in the colon 'date_created' and '2018-12-11' , how do I adjust my query??
Answer:
Use a function that will serve for two dd/mm/YYYY ou YYYY-mm-dd
inputs.
function inverteData($data){
if(count(explode("/",$data)) > 1){
return join("-",array_reverse(explode("/",$data)));
}elseif(count(explode("-",$data)) > 1){
return join("/",array_reverse(explode("-",$data)));
}
}
$data = "12/11/2018";
//para usar na query
$dataInvertida = inverteData($data); //2018-11-12
//alguma data retornada do select
$dataBanco = "2018-11-21";
$dataBancoInvertida = inverteData($dataBanco); // 21/11/2018
example on the ideone
$result_usuario = "SELECT * FROM vendas WHERE DATE(date_created) = '$dataInvertida' AND
tipo_venda = '$tipo_vendas' AND tipo = '$tipo_pagamento' ORDER BY 'id'";