Comparison and calculation of time and date [duplicate]

1

Well I retrieve the date and time of a record like this:

$sql = $conexao->query(select data, hora from pedido);
$resultado = mysqli_fetch_object($sql);

$resultado->data;
$resultado->hora;

I need to add 5 hours and check if the date is longer than each and current time.

How can I make this calculation is verification?

I wanted to see something like this

if ((data e hora da tabela com + 5 horas) => (data e hora atual)) {
 echo "o pedido já foi finalizado a mais de 5 horas";
}
    
asked by anonymous 31.08.2017 / 13:31

1 answer

0

In the case of comparison you can use something like this:

<?php
$horario = strtotime('1:00');
$abertura = strtotime('22:00');
$fechamento = strtotime('7:00');

if ((
        $abertura < $fechamento && $horario >= $abertura && $horario <= $fechamento
        ) || (
        $abertura > $fechamento && ($horario >= $abertura || $horario <= $fechamento)
        )) {
    echo 'aberto';
} else {
    echo 'fechado';
}

Source in SOPT itself

If you want to validate date and time, you can use this response from SOPT as well: Validate date and hour

    
31.08.2017 / 13:50