Obtain records from the previous day

3

What friends do I need to return the records of the previous day in CodeIgniter, what is the correct way to do it?

Here is the code in my model:

public function getOrdenes(){
    $this->db->where("fecha", date("Y-m-d"));
    $this->db->where("estado","1");
    $resultados = $this->db->get("pedidos");


    $return = array();

    foreach ($resultados->result() as $pedido)
    {
        $return[$pedido->id] = $pedido;
        $return[$pedido->id]->mesas = $this->getPedidosMesas($pedido->id); // Get the categories sub categories
    }

    return $return;
}
    
asked by WilsonicX 31.08.2018 в 16:35
source

2 answers

4

Look with the English friends, and I found a solution and if it worked, I leave the answer here:

public function getOrdenesPendientes(){
    $this->db->where("fecha", date("Y-m-d",strtotime("-1 days")));
    $this->db->where("estado","1");
    $resultados = $this->db->get("pedidos");


    $return = array();

    foreach ($resultados->result() as $pedido)
    {
        $return[$pedido->id] = $pedido;
        $return[$pedido->id]->mesas = $this->getPedidosMesas($pedido->id); // Get the categories sub categories
    }

    return $return;
}
    
answered by 31.08.2018 / 16:38
source
0

If you use SQL, it would fit like this:

SELECT *
FROM ordenes_pendientes
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 DAY);
    
answered by 04.09.2018 в 09:25