Check last records per hour

1

I'm wondering if you can get the last hour's data from the mysql database, the code below does the sum of values in the table for the last day,

   $busca = mysql_connect("$local","$usuario","$senha") or die("ERRO AO CONECTAR AO MYSQL, VERIFIQUE COM O ADMINISTRADOR" . mysql_error());
            mysql_select_db("$banco") or die("BASE DE DADOS INVÁLIDO");
            $pesquisa = mysql_query("SELECT sum(ProdValor) FROM vendas WHERE data BETWEEN CURRENT_DATE()-30 AND CURRENT_DATE()");
            while($sum = mysql_fetch_array($pesquisa)){
            $soma5 = $sum['sum(ProdValor)'];
            }
            //Mostrando o Resultado

            //$resultado = number_format($soma,2,",",".");

            echo $soma5;
    
asked by anonymous 29.03.2015 / 19:51

2 answers

1

For me what did Sergio said:

WHERE data >= DATE_SUB(NOW(), INTERVAL 1 HOUR)

Maybe it's because in the field structure in your table you just put DATE , put DATETIME equal here because it worked for me.

    
04.11.2016 / 21:42
0

There's this way too:

$data_hora_intervalo = 
    date('Y-m-d H:i:s', strtotime('-1 hour', strtotime(date('Y-m-d H:i:s'))));

where data>='$data_hora_intervalo'
    
05.11.2016 / 13:54