2011-02-02 14 views

Odpowiedz

89

To wygląda co trzeba:

$this->db->where('order_date >=', $first_date); 
$this->db->where('order_date <=', $second_date); 
return $this->db->get('orders'); 
+0

czy mogę użyć tego kodu na polu datetime.? –

+0

@ThorpeObazee co jeśli mam dwie cyfry i chcę, aby wprowadzony numer był pomiędzy lub nie? –

9

Spróbuj tego:

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

nadzieję, że to będzie działać

0

Maj to pomocne dla Ciebie .... Z łączeniem trzech tabel

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
$query = $this->db 
       ->get_where('orders',array('order_date <='=>$first_date,'order_date >='=>$second_date)) 
       ->result_array(); 
3

Ten pracował dla mnie świetnie

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

Działa doskonale dzięki @Madhu – amyogiji

0

Jeśli chcesz porównać daty SQL, można spróbować to:

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

który pracował dla mnie (PHP i MySQL) .

0

jeśli chcesz wymusić użycie słowa kluczowego BETWEEN na pomocniku zapytań Codeigniter. Możesz użyć tam, gdzie bez ucieczki fałszywe jak ten kod. Działa dobrze w wersji CI 3.1.5. Nadzieję, że ktoś jej pomoże.

if(!empty($tglmin) && !empty($tglmax)){ 
     $this->db->group_start(); 
     $this->db->where('DATE(create_date) BETWEEN "'.$tglmin.'" AND "'.$tglmax.'"', '',false); 
     $this->db->group_end(); 
    } 
Powiązane problemy