Checking remaining days between current date and contact deadline

Asked

Viewed 2,074 times

5

Good afternoon everyone, as per the code below, I am not being able to check the remaining days between $data and $prazocontact.

$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> 
    ";
}

inserir a descrição da imagem aqui

  • 2

    What’s the problem? There’s less lost sign on that line $prazo = - $ValorUm + $ValorDois;

  • Describe your problem better... besides what colleague @rray described, I couldn’t identify anything else that might be a problem.

  • $Value = $date; Where the variable $date comes from?

  • 1

    It comes from the @Magichat database, I just edited it, actually ;and $data.

  • Won’t the "Missing" column always show the same values? The way it is there makes it seem like a Countdown.

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');

0

You’re putting

$ValorUm = $date;

The variable you created is date and not Date, you are putting with "e" instead of "a" at the end and so it is going wrong.

$ValorUm = $data;

Whereas you need the difference between the two (to know how many days 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 
  • I just edited @Diéfani, but the result remains the same

  • @Maurosantos is your code displaying the other variables? I mean, the id and service name appears correctly printed on the screen?

  • Yes @Diéfani... I’m just not managing to add the date between the current month and the following month, the values in the current month are adding up correctly. http://chat.stackexchange.com/rooms/42587/discussion-between-magichat-and-mauro-santos

  • Just to put me right, you have the date and the contact date, you want to know how many days are left to the deadline? 'Cause I was thinking, the right thing wouldn’t be to calculate the difference between them?

  • You are correct @Diéfani, I’m wondering how many days to miss the deadline.

  • @Maurosantos look at my reply edition, try to do and see if it works.

  • ta giving error here $diff = strtotime($data_final) - strtotime($data_initial);

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.