user2673735
user2673735

Reputation: 81

Get rows that are past due from database

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

Answers (3)

Invincible Wahid
Invincible Wahid

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

Ari Djemana
Ari Djemana

Reputation: 1249

$query = $this->db->get_where('practice', array('DATE_FORMAT(due_date, "%Y-%m-%d") <' => date('Y-m-d')));

Upvotes: 0

Ram RS
Ram RS

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

Related Questions