JayJay
JayJay

Reputation: 23

Codeigniter Model fetch rows from -7 days

How do I fetch all of the rows that have a duedate -1 days from current day?

public function getNumTasksDueTomorrow() 
{
    $this->db->select('*');
    $this->db->from('tasks'); 
    $this->db->where("user_id",$this->session->userdata('user_id'));  
    $this->db->order_by("tasks_id", "desc");    
    $this->db->where("tasks_duedate", ' -1 day from current day');

    $query_result=$this->db->get();
    $result=$query_result->row();
    return $result;
}      

Upvotes: 1

Views: 1368

Answers (1)

PaulD
PaulD

Reputation: 1171

First get a mysql date for yesterday something like:

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

Then change your date query to:

$this->db->where("tasks_duedate <", $date);

This will give you all tasks with a due date older than yesterdays date. However I think you mean any date in the past, so just change $date to now.

 $date = date('Y-m-d H:i:s');

And of course I have assumed your date record is a mysql timestamp, you may have used a date, just remove the time formats.

Hope that helps,

Paul.

Upvotes: 1

Related Questions