Countdown of days to a future event

Asked

Viewed 693 times

0

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

I managed to create php that says the date that closes 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 is returning the days as -17336.

  • I didn’t understand the "I managed to create php that says the date that closes the registration."

  • Sorry, I managed to display the final date that closes the registration, which is 6 months after the registration date $row_curriculos['created'];

1 answer

2

Your mistake is on this line:

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

You already have the schedule of the event, it is itself $timestamp. You don’t have to do anything on top of it. Just use it directly in the subtraction:

$diferenca = $timestamp - $dia_hora_atual;

http://ideone.com/jXr0KV

  • ok, I really didn’t need to use the $dia_hora_evento, but the error continues, I think it is in the variable, that are returning the date with time, $row_curriculos['created']; = 19-06-2017:08:32:01.&#A;I tried several options to edit the variable by entering date(d-m-Y, $row_curricula['created']);, but it didn’t work. Inserting the full date works, but using the variable does not work.

  • 1

    Solved, in my database was the type Coomo datetime, I changed to date and worked correctly, the way I wanted.

Browser other questions tagged

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