Working with date and deadline checks

0

I am a logics problem in my application. Galera is the following, in the project module of my system there is a deadline for project delivery. I need to know the following.

  

If today is 1 week (7 Days) before the deadline, send the yellow to the status column (These colors I've already implemented is missing the rsrsr logic)

     

If today is 2 Weeks (14 Days) before the deadline, please check Green for status column.

     

If red command burst

So far I've only checked whether or not it crashed with a basic logic variable $recebeData = End Date of the project variable $ diaTime - '

<?php
            $recebeData = date_converter($date);
            $diaHoje = date('Y-m-d');
            if(strtotime($recebeData) >= strtotime($diaHoje)){
                }
                  jogo verde no status
        else {
               jogo vermelho no status
}
        ?>

Help me make yellow play if it's missing 7 days before deadline and green if it's missing 14 days before!

    
asked by anonymous 10.05.2016 / 02:26

3 answers

0

Well, assuming you receive the date from a database and do this check in php, you can use the Datetime-> diff () class. Even this has already been discussed here .

I tried to use the same variable names of your system for better understanding.

$recebeData = new DateTime( '2016-05-08' );
$diaHoje = new DateTime();

$dias = $recebeData->diff( $diaHoje );

if (($dias->days) > 14) {
    echo '<div style="background: red; width: 200px; height: 200px"><div>';
}elseif (($dias->days) > 7) {
    echo '<div style="background: green; width: 200px; height: 200px"><div>';
}else{
    echo '<div style="background: yellow; width: 200px; height: 200px"><div>';
}

Explaining the code better, the variable $ receivesData will receive the end date of the project.

The variable $ diaHoje obviously receives the current date, and $ days calculates the running days. If you want to show the total days, you can display the object $ days-> days.

Then an if was made using the informed color parameter and an echo with a simple box illustrating the colors.

    
10.05.2016 / 04:31
0

Thank you so much for the help. But I solved the problem with the following logic

'; echo "TODAY:" $ today; echo ''; echo "EXPIRED:" $ bd_vencido; echo ''; echo "5 DAYS:". $ bd_5dias; echo ''; echo "8 DAYS:". $ bd_8days; echo '';

// put one of the options here: // $ bd_vencido // $ bd_5days // $ bd_8days $ bd = $ today;

if ($ bd

10.05.2016 / 14:01
-1

For the sake of performance, have the database compute the difference between the dates. See mysql's DATEDIFF () function Click here to see example .

Assuming that the date return is returned in the variable timeout in this case check below and use the $ status variable to pass a CSS class name.

So when you do the html, include a class in the span tag. Ex: <span class="<?echo $status;?>"</span>

//Verifica se está entre 1 e 7 dias
if ($tempoConclusao > 0 && $tempoConclusao <= 7 ) {
                    $status = "corAmarelo";
} 
//se o prozo é maior que 7 dias
elseif ($tempoConclusao > 7) {
      $status = "corVerde";
} 
//tempo negativo, ou seja, já estourado
else {
      $status = "corVermelho";
}
    
10.05.2016 / 03:50