Reputation: 81
I am using codeigniter and I am trying to get all rows from a database table that are past due and only the ones that are past due.
The table includes a column that is titled due_date
and is formatted as a datetime
Past Due
stands for anything with a due_date
prior to todays date. So for example, if the due date was 04/25/2014 and todays date was 04/26/2014 it would be considered overdue.
My code is as follows:
$query = $this->db->get_where('practice', array('due_date' => date('Y-m-d')));
return $query->result();
But wouldn't that return everything due today? Not quite what I want.
A row would look something like this for the due_date column
2014-04-23 00:00:00
Upvotes: 0
Views: 126
Reputation: 59
Try This :
$query=$this->db
->where('DATE_FORMAT(due_date, "%Y-%m-%d") <',"date('Y-m-d')")
->get('practice');
Source: [How to select date from datetime column?
Upvotes: 1
Reputation: 1249
$query = $this->db->get_where('practice', array('DATE_FORMAT(due_date, "%Y-%m-%d") <' => date('Y-m-d')));
Upvotes: 0
Reputation: 277
Quick Google search gives me a solution where this should be possible:
$query = $this->db->where('practice', array('due_date <' => date('Y-m-d')))->get();
Source: http://ellislab.com/codeigniter/user-guide/database/active_record.html
Upvotes: 0