CodeIgniter Forums

Full Version: Using get_where to get data between today and last x days from database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is working:

PHP Code:
$this->db->select('*');
$this->db->where('payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()');
$this->db->where('vendor'$id);
$data['dash_sale_d'] = $this->db->get('sale'); 


This is not:

PHP Code:
$data['dash_sale_d'] = $this->db->get_where('sale', array('vendor' => $id'payment_timestamp' => 'BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()')); 


What am I missing?
As you are passing BETWEEN... as a value it's being escaped.

Maybe you can do it like:
'payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => NULL
'payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => FALSE
'payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => ''
(01-07-2019, 01:32 PM)jreklund Wrote: [ -> ]As you are passing BETWEEN... as a value it's being escaped.

Maybe you can do it like:
'payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => NULL
'payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => FALSE
'payment_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => ''

It's working now!

Thank you!