我有一个created_at 字段,格式为yy-mm-dd hr-min-sec .. 现在如何仅选择该字段的日期部分?
function customers(){
$this->datatables
->select('created_at')
->group_by('email')
->from('customers')
echo $this->datatables->generate();
}
如何注册这些东西?
我有一个created_at 字段,格式为yy-mm-dd hr-min-sec .. 现在如何仅选择该字段的日期部分?
function customers(){
$this->datatables
->select('created_at')
->group_by('email')
->from('customers')
echo $this->datatables->generate();
}
如何注册这些东西?
Set the value from the created_at field to $result then
$date = new DateTime($result);
echo $date->format('Y-m-d');
You can do in the query with the SUBSTRING command:
->select('SUBSTRING(created_at,1,8)')
(note the first character starts at index 1)
However it would be better performance-wise to do it in the resulting PHP code.
echo substr($data->created_at,0,8);
您需要使用DATE()
功能,您的查询应该看起来像
->select("DATE(`created_at`) AS created_at",FALSE) // to avoid additional bacticks
期待您使用 MYSQL
http://dev.mysql.com/doc/refman/5.0/fr/date-and-time-functions.html
function customers(){
$this->datatables
->select('DATE_FORMAT(created_at, '%Y/%m/%d') as view_created_at')
->group_by('email')
->from('customers')
echo $this->datatables->generate();
}
然后你只需要做 view_created_at;