Database date between query build file in CodeIgnitor administrator

Here’s the path to DB file in CodeIgnitor admin end which contains query related stuff. Like building order, qhere and select blocks. One may want to do some debugging in this file. In this file i need to make no changes. Just for reference.

/administrator/system/database/DB_active_rec.php

Now here’s how once could make a BETWEEN query for a date field. I wanted records for last 30 days.

$this->db->where('`orderDateCreated` BETWEEN SYSDATE() - INTERVAL 30 DAY AND SYSDATE()', NULL, FALSE);
$query = $this->db->get('order');

if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
}
}

My “orderDateCreated” field contained hour, minutes seconds i.e. it is a “datetime” field that’s why i needed to put SYSDATE here. If this field were just “date” field then i could i replace SYSDATE with CURDATE to make it:

orderDateCreated` BETWEEN SYSDATE() - INTERVAL 30 DAY AND SYSDATE()

Leave a Reply

Your email address will not be published. Required fields are marked *