CodeIgniter Forums
[Solved] Count All Result Where Now Date + 2 Days - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: [Solved] Count All Result Where Now Date + 2 Days (/showthread.php?tid=63876)



[Solved] Count All Result Where Now Date + 2 Days - wolfgang1983 - 12-17-2015

Hello I would like to know if this is possible and what best way to go about it is

I have a column on my data base table calendar called date and it displays year-month-day

What I am trying to do is get the total number of rows between now() and + 2 days

But so far I am unable to do so


PHP Code:
public function test() {
 
   $this->db->select('*');
 
   $this->db->from('calendar');
 
   $this->db->where('date BETWEEN DATE_ADD(date("Y-m-d"), INTERVAL 2 DAY) AND date("Y-m-d")');
 
   $result $this->db->count_all_results();
 
   return $result;



How could I achieve it?

Update:

I have found this date code below and work it with my function is it correct? Just not sure if safest way.

PHP Code:
public function test() {
 
       $date date('Y-m-d'mktime(000date('m'), date('d') + 3date('Y')));
 
       $this->db->where('date <'$date);
 
       $query $this->db->get('calendar');
 
       return $query->num_rows();
 
   



RE: Count All Result Where Now Date + 2 Days - skunkbad - 12-17-2015

Maybe this:


Code:
SELECT * FROM `calendar` WHERE `date` BETWEEN NOW() AND ( CURDATE() + INTERVAL 2 DAY );



RE: Count All Result Where Now Date + 2 Days - Bhavesh - 12-17-2015

(12-17-2015, 09:08 PM)skunkbad Wrote: Maybe this:


Code:
SELECT * FROM `calendar` WHERE `date` BETWEEN NOW() AND ( CURDATE() + INTERVAL 2 DAY );

Yes, this is perfect.


RE: Count All Result Where Now Date + 2 Days - wolfgang1983 - 12-18-2015

(12-17-2015, 09:08 PM)skunkbad Wrote: Maybe this:


Code:
SELECT * FROM `calendar` WHERE `date` BETWEEN NOW() AND ( CURDATE() + INTERVAL 2 DAY );

How would I do it the active record way? with the between etc