Checking days remaining between current date and deadline for contact [duplicate]

5

Good afternoon folks, as per the code below, I can not check the remaining days between $ date and $ prazocontato.

$consulta = mysql_query("
        SELECT s.id_cliente, p.nome_servicos, s.data, s.prazocontato, s.email, s.vaifazerservicos 
        FROM dadoscliente AS s 
        INNER JOIN servicos2 AS p 
        ON p.id_servicos = s.vaifazerservicos 
        ORDER BY s.id_cliente DESC 
        LIMIT $start, $limite");

        while ($linha = mysql_fetch_array($consulta)) {
        $id_cliente = $linha['id_cliente'];
        $nome_servicos = $linha['nome_servicos'];
        $data = date('d/m/Y', strtotime($linha['data']));
        $prazocontato = date('d/m/Y', strtotime($linha['prazocontato']));

    $ValorUm = $data;
    $ValorDois = $prazocontato;
    $prazo = $ValorUm + $ValorDois;
        ?>        

<?php if($prazo == 0){
            echo "
<tr>
    <td>$id_cliente</td>
    <td>$nome_servicos</td>
    <td>$data</td>
    <td>$prazocontato</td>
    <td style='color:blue;'><b>ENCERRA HOJE!</b></td>
    <td><a href='editar.php?id_cliente=$id_cliente'><img src='img/editar3.png' title='Editar'></a></td>
</tr> 

    ";
}elseif($prazo < 0){
    echo "
<tr>
    <td>$id_cliente</td>
    <td>$nome_servicos</td>
    <td>$data</td>
    <td>$prazocontato</td>
    <td style='color:red;'><b>ENCERRADO!</b></td>
    <td style='visibility: hidden;'><a href='editar.php?id_cliente=$id_cliente'><img src='img/editar3.png' title='Editar'></a></td>
</tr>   

    ";
}else{
    echo "
<tr>
    <td>$id_cliente</td>
    <td>$nome_servicos</td>
    <td>$data</td>
    <td>$prazocontato</td>
    <td>$prazo Dia(s)</td>
    <td><a href='editar.php?id_cliente=$id_cliente'><img src='img/editar3.png' title='Editar'></a></td>
</tr> 
    ";
}

    
asked by anonymous 25.07.2016 / 20:39

2 answers

3
  

Try this

$data_inicial = new DateTime($linha['data']); 
$data_final = new DateTime($linha['prazo_contato']); 
$diferenca = $data_inicial->diff( $data_final ); 
$diferenca = $diferenca->format('%d days');
    
26.07.2016 / 17:05
0

You're putting

$ValorUm = $date;

The variable you created is dated and does not date, you are putting it with "and" instead of "a" in the end and so it is going wrong.

$ValorUm = $data;

Considering that you need the difference between the two (to know how many days are missing between one and the other) do

 $data_inicial = $linha['data'];
    $data_final = $linha['prazo_contato'];

     // Calcula a diferença em segundos entre as datas
     $diferenca = strtotime($data_final) - strtotime($data_inicial);

     //Calcula a diferença em dias 
     $prazo = floor($diferenca / (60 * 60 * 24)); //floor(); é usado para arredondar 
    
25.07.2016 / 21:10