Create conditional comparing current date with registration date

0

I need help with conditionals using dates ..

I need when creating a record the cell of the table is colored verde ,

By passing 3 days after the record was created, the cell is automatically naranja

and when going from 6 days to roja ...

I did something in which I change the color manually, but I would like it to be automatic using dates ...

This is what I have ... Thank you:

<?php
foreach ($respuesta as $registro) {
$tr = '<tr>';
    if ($registro['idEstado'] == '1') {
        $tr = '<tr style="background-color:#F98888;color:#B72212;">';
    }else if ($registro['idEstado'] == '2') {
        $tr = '<tr style="background-color:#F9BD88;color:brown;">';
    } else {
        $tr = '<tr style="background-color:#B7D5B6;color:green;">';
    }

$cadena .= $tr."

            <td>".$registro['fecha']."</td>
            <td>".$registro['nombre']."</td>
            <td>".$registro['direccion']."</td>
            <td>".$registro['telefono']."</td>
            <td>".$registro['estados']."</td>
        </tr>";         
}
echo $cadena;

?>
    
asked by Dev w 11.08.2018 в 19:54
source

1 answer

0

Reading your code I come to the conclusion that you need something like this:

<?php

    //creas la fecha actual 
    $fecha_hoy = date('Y-m-d H:i:s');
    //traemos la fecha de la base de datos y le sumamos 3 dias...
    $fecha_registro= date($registro['fecha'], strtotime('+3 days');


    $tr = '<tr>';
    //comparamos las fechas que la fecha de registro no sea mayo a la fecha de hoy
    if ($fecha_hoy > $fecha_registro) {
        //si esto se cumple es por que ya han pasado mas de 3 dias
        $tr = '<tr style="background-color:#F98888;color:#B72212;">';
    }

?>

I hope you serve, Here I leave the Link for you to illustrate mejos and understand the operation.

ReNiceCode ...

    
answered by 11.08.2018 в 20:06