2017-09-05 75 views
2

我在這裏導出爲CSV格式表的結果,我想格式化日期列這樣的事情2017年8月31日,13時10分12秒笨 - 導出表記錄到CSV與日期格式

有人幫我修改這個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); 
} 
+0

https://dev.mysql.com/doc/refman/5.5/en/date -and-time-functions.html#function_date-format – rtfm

+0

[MySQL date format change]可能重複(https://stackoverflow.com/questions/21463001/mysql-date-format-change) – RealCheeseLord

+0

@RealCheeseLord我檢查過查詢但在CSV/Excel文件中,日期列顯示空白值 – Arsee

回答

3

Arsee,讓你嘗試用這個查詢SELECT DATE_FORMAT(FROM_UNIXTIME( created_on ), '%e %b %Y') AS OrderDate,

1

更改您這樣的查詢

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

注:訂購日期之間的空間應該被刪除

+0

它仍然顯示csv – Arsee

+0

中的空白值然後檢查喲中的任何語法錯誤你的導出功能 –