0

有人可以告诉我如何使用 codeigniter 正确使用以下查询:

DATE_FORMAT(sr.dateCreated,'%m/%d/%Y @ %h:%i %p') AS dateCreated 

我试过了:

 public function viewSR($id) {
        $this->db->select('sr.id
                            ,sr.woid
                            ,sr.description
                            ,DATE_FORMAT(sr.dateCreated),'%m/%d/%Y @ %h:%i %p') AS dateCreated
                            ,sr.startTime
                            ,sr.endTime
                            ,rt.name AS rateName'); 
        $this->db->from('service_report sr');

任何帮助将不胜感激!

4

1 回答 1

0

尝试像这样更改您的代码:

    public function viewSR($id) {
      $this->db->select("sr.id
                        ,sr.woid
                        ,sr.description
                        ,DATE_FORMAT(sr.dateCreated,\"%m/%d/%Y @ %h:%i %p\") AS dateCreated
                        ,sr.startTime
                        ,sr.endTime
                        ,rt.name AS rateName",FALSE); 
     $this->db->from('service_report AS sr');

或尝试以这种方式修改您的代码:

function list_all($lang, $limit = FALSE, $offset = FALSE)
{

    $this->db->select('*');
    $this->db->select("DATE_FORMAT(datetime, '%d.%m.%Y à %H:%i:%s') AS datetime");

    $this->db->where('lang', $lang);
    $this->db->limit($limit);
    $this->db->offset($offset);
    $this->db->order_by('datetime', 'desc');
    $query = $this->db->get('news');

    return $query->result();
} 
于 2013-07-09T06:20:42.533 回答