CodeIgniter Forums
Using get_where to get data between today and last x days from database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Using get_where to get data between today and last x days from database (/thread-72577.html)



Using get_where to get data between today and last x days from database - castle - 01-07-2019

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?


RE: Using get_where to get data between today and last x days from database - jreklund - 01-07-2019

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()' => ''


RE: Using get_where to get data between today and last x days from database - castle - 01-07-2019

(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!