duanan2732 2017-09-05 06:02
浏览 61
已采纳

Codeigniter - 使用日期格式将表记录导出为CSV

here I am exporting the table result in CSV format and I want to format the date column something like this 2017-08-31, 13:10:12

anyone help me to modify this mySql query

$query = "SELECT DATE_FORMAT(created_on,'%Y-%m-%d , %H:%i:%s') AS OrderDate,transaction.order_id,transaction.payment_method FROM transaction";

and here is my Export to CSV function

function ExportCSV()
{
    $this->load->dbutil();
    $this->load->helper('file');
    $this->load->helper('download');
    $delimiter = ",";
    $newline = "
";
    $filename = "lugmah_sales_report.csv";
    $query = "SELECT DATE_FORMAT(created_on,'%Y-%m-%d , %H:%i:%s') AS OrderDate,transaction.order_id,transaction.payment_method FROM transaction";
    $result = $this->db->query($query);
    $data = $this->dbutil->csv_from_result($result, $delimiter, $newline);
    force_download($filename, $data);
}
  • 写回答

2条回答 默认 最新

  • douqiu1604 2017-09-05 07:18
    关注

    Arsee, Better you try with This query SELECT DATE_FORMAT(FROM_UNIXTIME(created_on), '%e %b %Y') AS OrderDate,

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?