Welcome Guest, Not a member yet? Register   Sign In
[Solved] Count All Result Where Now Date + 2 Days
#1

(This post was last modified: 12-25-2015, 11:23 PM by wolfgang1983.)

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();
 
   
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

Maybe this:


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

(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.
Reply
#4

(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
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB