我有一个名为tbl_user的表,其中user_added_date是DATETIME (Y-m-d H:i:s)
类型。
我正在尝试使用以下活动记录来获取所有数据: -
$this->db->select('user_name AS Name, user_username AS Username,
user_mobile AS Mobile,
DATE(user_added_date) AS `Joining Date`');
$dataResult = $this->db->get('user');
现在,我以mm/dd/YYYY
格式获取数据。
如何以dd-mm-YYYY格式获取数据?
在我更新Gordon先生所说的答案之后,我面临的问题是更具体的问题。
更新后的有效记录
$this->db->select('user_name AS Name,
user_username AS Username,
user_mobile AS Mobile,
DATE_FORMAT( user_added_date, "%d-%m-%Y" ) AS `Joining Date`,
DATE(user_last_activity) AS `Last Time Active`');
$dataResult = $this->db->get('user');
产生此错误: -
Error Number: 1054
Unknown column '"%d-%m-%Y"' in 'field list'
SELECT `user_name` AS Name, `user_username` AS Username, `user_mobile` AS Mobile, DATE_FORMAT( user_added_date, `"%d-%m-%Y"` ) AS `Joining Date`, DATE(user_last_activity) AS `Last Time Active` FROM (`tbl_user`)
Filename: /var/www/html/custom/ci/tharjumal/controllers/admin/user.php
Line Number: 103
这更多是由于活动记录属性封装了"%d-%m-%Y"在一个(`)符号内,因此将其视为一个列。
如何解决此问题?
答案 0 :(得分:3)
您可以在查询中使用date_format()
:
$this->db->select('user_name AS Name, user_username AS Username,
user_mobile AS Mobile,
date_format(user_added_date, "%d/%m/%Y") AS `Joining Date`');