codeigniter Date_Format in DB-> select

时间:2013-07-09 05:57:23

标签: codeigniter

有人可以告诉我如何使用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');

任何帮助都会非常感激!

1 个答案:

答案 0 :(得分: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();
}