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条)

报告相同问题?

悬赏问题

  • ¥15 Unity3D WebView
  • ¥20 论文AlphaTensor复现(有偿)
  • ¥15 (有偿)在ANSYS中 .anf文件
  • ¥45 关于#芯片#的问题:组合逻辑电路设计
  • ¥15 基与机器学习和时间序列分析预测养老服务需求趋势
  • ¥100 求连续两帧图像在水平和垂直上偏移
  • ¥15 mysql全文索引查找指定必须关键词word无效
  • ¥15 Verilog hdl密码锁设计
  • ¥35 基于python的有ssl加密传输的socket聊天室
  • ¥15 数码管亮度控制器设计