gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:35:52 25 4
gpt4 key购买 nike

我在这里以 CSV 格式导出表格结果,我想将日期列格式化为这样的格式 2017-08-31, 13:10:12

有人帮我修改这个mySql查询

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

这是我导出到 CSV 的功能

function ExportCSV()
{
$this->load->dbutil();
$this->load->helper('file');
$this->load->helper('download');
$delimiter = ",";
$newline = "\r\n";
$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);
}

最佳答案

Arsee,最好尝试使用此查询 SELECT DATE_FORMAT(FROM_UNIXTIME(created_on), '%e %b %Y') AS OrderDate,

关于php - Codeigniter - 使用日期格式将表记录导出到 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46047934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com