mardi 27 février 2018

Expiration date

I have 4 dates store in database named as show_first, show_second, show_third and show_fourth.

I wanth that PHP check dates stored in database and then display correct $prijavni_rok. If current date is bigger then value stored in $show_first then its need to check show_second and again if current date is bigger then show_second needs to check value in stored in show_third. If all values are smaller then current date then it is need to $prijavni_rok to be "ZAPRTO - DNI; "number of days"". Now it is only displaying like this: ZAPRTO - DNI; 17588

It is only working if I put dates directly like this: $first = strtotime('2017-12-31'); and I adjust code just for show_first.

    $current_date = date('Y-m-d');

    $show_date = $row['show_date'];
    $show_first = $row['show_first'];
    $show_second = $row['show_second'];
    $show_third = $row['show_third'];
    $show_four = $row['show_four']; 

    $date = strtotime($current_date);
    $show = strtotime($show_date); 
    $first = strtotime($show_first);
    $second = strtotime($show_second);
    $third = strtotime($show_third);
    $four = strtotime($show_four); 

    if ($date < $first) {
        $diff = $date-$first;
        $x=abs(floor($diff / (60 *60 * 24)));
        $prijavni_rok = "ODPRT - PRVI ROK";
    } else {    
        if ($date < $second) {
            $diff = $date-$second;
            $x=abs(floor($diff / (60 *60 * 24)));
            $prijavni_rok = "ODPRT - DRUGI ROK";
            $prijavni_dni = "DNI; ".$x;
        } else {
            if ($date < $third) {
                $diff = $date-$third;
                $x=abs(floor($diff / (60 *60 * 24)));
                $prijavni_rok = "ODPRT - TRETJI ROK";
                $prijavni_dni = "DNI; ".$x;
            } else {
                if ($date < $four) {
                    $diff = $date-$four;
                    $x=abs(floor($diff / (60 *60 * 24)));
                    $prijavni_rok = "ODPRT - ČETRTI ROK";
                    $prijavni_dni = "DNI; ".$x;
                } else {
                    $diff = $date-$four;
                    $x=abs(floor($diff / (60 *60 * 24)));
                    $prijavni_rok = "ZAPRTO";
                    $prijavni_dni = "DNI; ".$x;
                } 
            } 
        } 
    }

Aucun commentaire:

Enregistrer un commentaire