Working with date and deadline checks

Asked

Viewed 81 times

0

I’m a logical problem in my application. Guys, here’s the thing, in the project module of my system there is a deadline for delivery of the project. I need to know the following.

If today’s day is 1 week (7 Days) before the deadline, mandoamarelo to status column(These colors have already been implemented only lack the logic rsrsr)

If today is 2 Weeks (14 Days) before the deadline, send Green to status column.

If blown I send red

so far I have only checked whether this burst or not with a basic logic variable $recebeData = Final date of the project variable $diaHoje --'

<?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 to play yellow if you miss 7 days before deadline and green if you miss 14 days before!

3 answers

0

Well, assuming you get the date of a database and do this check in php, you can use the class Datetime->diff(). Even that has been dealt with 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 $receive will receive the final date of the project.

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

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

0

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

'; echo "TODAY: ". $today; echo ''; echo "EXPIRED: ". $bd_expired; echo ''; echo "5 DAYS: ". $bd_5days; echo ''; echo "8 DAYS: ". $bd_8days; echo '';

//put here one of the options: // $bd_expired // $bd_5dias // $bd_8dias $bd = $today;

if ($bd <= $today) { echo "defeated - red"; } Isis { if ($bd > ($today + 604800)) { echo "more than 7 days - green"; } Isis { echo "less than 7 days left - yellow;"; } }

?> worth to all

-1

For performance reasons, have the database calculate the difference between dates. See mysql’s DATEDIFF() function Click here for example.

Assuming the return of dates is returned in the variable $time then check below and use the $status variable to pass a CSS class name.

So when you do 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";
}

Browser other questions tagged

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