Date Comparison (status to expire)

0

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

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

If date_crl is less than the current date: DEFAULT.

If date_crl is missing 30 days or less to win: ALERT

Am I having trouble getting these 30 days?

    
asked by anonymous 11.05.2017 / 15:50

1 answer

1

example - ideone

The main function used in the example was strtotime

  

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

//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";
}
    
11.05.2017 / 17:45