2
I have this script in my code:
$sql = "SELECT * FROM os WHERE status2 <> 'Fechado' ORDER BY XXXXXXX ";
$resultado = mysql_query($sql) or die ("Erro na consulta");
while ($linha = mysql_fetch_assoc($resultado)) {
$vencimento = $linha["vencimento"];
$a = explode("-","$vencimento");
$b = explode("-","$hoje");
$antiga= mktime(0, 0, 0, $b[1], $b[2], $b[0]);
$atual= mktime(0, 0, 0, $a[1], $a[2], $a[0]);
$diferenca= $atual-$antiga;
$dias = floor($diferenca/84600);
echo $dias = (int) $dias;
}
Where it returns how many days are left to the x due. My Doubt is how to Sort query in Mysql by record with nearest due dates.
Example below:
Sendo Hoje - dia 10/01
data_entrada | vencimento | Dias
01/01 | 05/01 | - 5 "Dias Atrasado"
01/01 | 11/01 | 1 "Para Vencer"
01/01 | 12/01 | 2 "Para Vencer"
01/01 | 13/01 | 3 "Para Vencer"
01/01 | 14/01 | 4 "Para Vencer"
Hello I don’t have much experience, could you explain your consultation? in the case I understood (Maturity , KURDATE()) which is the current date,'--dias_to maturity'-- what would be?
– Fabio Henrique
dias_for_due is only one alias (nickname) for the number of days remaining for maturity. Then I use this same alias to sort the results.
– Rodrigo Rigotti