codeigniter中的日期比较

时间:2013-06-10 16:15:14

标签: mysql sql codeigniter

此处日期的格式为yy-mm-dd hr:min:sec,其中$ this-> get('on')的格式为yy-mm-dd。那么现在如何比较这两个值?

function customer_get()
{
        $this->db->select('user_id,first_name,last_name,email');
        $this->db->from('customers');
        $this->db->join('orders', 'user_id = customer_user_id','inner');
        $array = array('Date' => $this->get('on'));
        $this->db->where($array);
        $query = $this->db->get();
        if($query)
        {
                $this->response($query->result(),200);
        }
        else
        {
                $this->response(NULL, 404);
        }
}

1 个答案:

答案 0 :(得分:0)

啊,您需要为查询正确设置日期格式:

function customer_get()
{

        $this->db->select('user_id,first_name,last_name,email');
        $this->db->from('customers');
        $this->db->join('orders', 'user_id = customer_user_id','inner');
        $this->db->where('DATE(`Date`)', $this->get('on'), false);
        $query = $this->db->get();
        if($query)
        {
                $this->response($query->result(),200);
        }
        else
        {
                $this->response(NULL, 404);
        }

}