Getting data posted in between two dates

后端 未结 10 1720
无人及你
无人及你 2020-12-08 00:15

How can I retrieve data from the database by querying records between two dates using CodeIgniter\'s activerecord?

相关标签:
10条回答
  • 2020-12-08 01:12

    This looks like what you need:

    $this->db->where('order_date >=', $first_date);
    $this->db->where('order_date <=', $second_date);
    return $this->db->get('orders');
    
    0 讨论(0)
  • 2020-12-08 01:13

    May this helpful to you.... With Join of Three Tables

    public function get_details_beetween_dates()
        {
            $from = $this->input->post('fromdate');
            $to = $this->input->post('todate');
    
            $this->db->select('users.first_name, users.last_name, users.email, groups.name as designation, dailyinfo.amount as Total_Fine, dailyinfo.date as Date_of_Fine, dailyinfo.desc as Description')
                        ->from('users')
                        ->where('dailyinfo.date >= ',$from)
                        ->where('dailyinfo.date <= ',$to)
                        ->join('users_groups','users.id = users_groups.user_id')
                        ->join('dailyinfo','users.id = dailyinfo.userid')
                        ->join('groups','groups.id = users_groups.group_id');
    
            /*
            $this->db->select('date, amount, desc')
                     ->from('dailyinfo')
                     ->where('dailyinfo.date >= ',$from)
                     ->where('dailyinfo.date <= ',$to);
            */
    
            $q = $this->db->get();
    
            $array['userDetails'] = $q->result();
            return $array;
        }
    
    0 讨论(0)
  • 2020-12-08 01:16

    Try This:

    $this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');
    

    Hope this will work

    0 讨论(0)
  • If you want to compare SQL dates, you can try this:

    $this->db->select();
    $this->db->from('table_name');
    $this->db->where(' date_columnname >= date("'.$from.'")');
    $this->db->where( 'date_columnname <= date("'.$to.'")');
    

    That worked for me (PHP and MySQL).

    0 讨论(0)
提交回复
热议问题