• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using get_where to get data between today and last x days from database

#1
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?
Reply

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

#3
(01-07-2019, 02: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!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.