我有一个codeigniter
应用程序,我需要从year
数据类型的mysql字段中获取datetime
。我需要使用CI active record
使用以下方式执行此操作。
$this->db->select(YEAR("added_date"));
$this->db->from("news");
$this->db->order_by("added_date", "DESC");
$this->db->where('published', 1);
$this->db->distinct();
$this->db->get();
但是我收到以下错误:
Call to undefined function YEAR() in /opt/lampp/htdocs/...
我使用codeigniter 2.1.x(如果需要)
答案 0 :(得分:2)
YEAR
是一个MYSQL函数而不是codeigniter函数:
$this->db->select('YEAR(`added_date`)');