2011-02-02 11 views

Respuesta

89

Esto se parece a lo que necesita:

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

¿puedo usar este código en el campo de fecha y hora? –

+0

@ThorpeObazee ¿Qué pasa si tengo dos números y quiero que el número ingresado se encuentre entre medio o no? –

9

Prueba esto:

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

Hope esto funcionará

0

de mayo de este útil para usted .... Con la unión de tres tablas

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

Esto funcionó muy bien para mí

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

Funciona perfectamente gracias @Madhu – amyogiji

0

Si desea comparar las fechas de SQL, puede intentar esto:

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

que trabajó para mí (PHP y MySQL) .

0

si desea forzar el uso de la palabra clave BETWEEN en Codeigniter query helper. Puede usar donde sin escaparse falso como este código. Funciona bien en CI versión 3.1.5. Espero que ayude a alguien.

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