Date Comparison (status due)

Asked

Viewed 746 times

0

I have an informed date ($date_crl) and need to show an alert in 3 conditions:

If date_crl is greater than 30 days from current date: VIGENTE.

If date_crl is less than the current date: DUE.

If date_crl missing 30 days or less to win: ALERT

I’m having a hard time catching these 30 days?

  • How is this date formatted? You could put what you have already done or tried to do in your question?

1 answer

1


example - ideone

The main function used in the example was strtotime

the current date can be in qq valid format since it is equal to the $date_crl date format

//Exemplos de formato data atual
//$dataAtual = date("Y-m-d H:i:s");
//$dataAtual = date("d-m-Y");
//$dataAtual = date("Y-m-d");

$time_atual = strtotime($dataAtual);

$time_expira = strtotime($date_crl);

$dif_tempo = $time_expira - $time_atual;

$dias = (int)floor( $dif_tempo / (60 * 60 * 24));

if ($dias <= 30 && $dias > 0){
    echo "ALERTA";
}elseif($dias<0){
    echo "VENCIDO";
}else{
    echo "VIGENTE";
}
  • Okay, your answer really helped me figure out where I was going wrong. I made the change in IF and changed the post

  • Right, but the ALERT would be for 30 or less days. If it passes the date, then it is EXPIRED. That’s why I used the: $dias <= 30 && $dias > 0

  • What is your suggestion in this case ?

  • I edited the question so that the edition you made in the answer is in accordance with the desired.

  • ah ta, thanks Leo!

Browser other questions tagged

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