dt56449492 2016-09-10 12:56
浏览 46
已采纳

MySQL使用codeigniter中的格式选择日期

My Codeigniter site select date from a table as follows.

$this->db->select('reg_id, fname, lname, added_date');// working

MYSQL database has added_dateformat as 2016-09-10 14:44:46 Now i want to select data from table format should be 2016-09-10 14:44 PM

selecting date separately can get the format

SELECT DATE_FORMAT(added_date, '%Y-%m-%d %h:%i %p') FROM tble_reg

Then how to select other columns with added_date relevant format

$this->db->select('reg_id, fname, lname, DATE_FORMAT(added_date, '%Y-%m-%d %h:%i %p')'); 
//not working
  • 写回答

3条回答 默认 最新

  • douqian1835 2016-09-10 13:00
    关注

    This is speculation, but you might have the single quotes competing with each other. Does this work?

    $this->db->select('reg_id, fname, lname, DATE_FORMAT(added_date, "%Y-%m-%d %h:%i %p") as added_date');
    

    MySQL allows both single quotes and double quotes for string delimiters, which is handy in cases when single quotes are needed for delimiting strings at the application layer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?