Days countdown to a future event

0

A system that registers curricula, the curriculum is active for months after the registration date, which in my table is the variable $ row_curriculos ['created'];

I was able to create the php that says the date that ends the registration.

    <?php  
     $data = $row_curriculos['created']; 
     $timestamp = strtotime($data . "+6 months"); 
     echo date('d/m/Y', $timestamp);  
     ?>

Gostaria de exibir o numero de dias, exemplo:
Faltam XX dias para o cadastro expirar.

Tentei fazer assim:


  <?php
    $data = $row_curriculos['created'];
    $timestamp = strtotime($data . "+6 months");    
    $dia_hora_atual = strtotime(date("Y-m-d"));
    $dia_hora_evento = strtotime(date($timestamp));

    $diferenca = $dia_hora_evento - $dia_hora_atual;

    $dias = ($diferenca / 86400);
    echo "$dias dia(s)";
    ?>

But it's returning the days as -17336.

    
asked by anonymous 19.06.2017 / 22:13

1 answer

2

Your error is in this line:

$dia_hora_evento = strtotime(date($timestamp));

You already have the time of the event, it is the $timestamp itself. You do not have to do anything about it. Just use it directly in the subtraction:

$diferenca = $timestamp - $dia_hora_atual;

link

    
19.06.2017 / 22:45