0

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
user2673735
  • 81
  • 1
  • 5

3 Answers3

1

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?

Community
  • 1
  • 1
0

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

Ram RS
  • 278
  • 3
  • 17
0
$query = $this->db->get_where('practice', array('DATE_FORMAT(due_date, "%Y-%m-%d") <' => date('Y-m-d')));
Ari Djemana
  • 1,229
  • 12
  • 12