-1

我有一个created_at 字段,格式为yy-mm-dd hr-min-sec .. 现在如何仅选择该字段的日期部分?

function customers(){

    $this->datatables
    ->select('created_at')
    ->group_by('email')
    ->from('customers')

    echo $this->datatables->generate();
}

如何注册这些东西?

4

4 回答 4

0

Set the value from the created_at field to $result then

$date = new DateTime($result);
echo $date->format('Y-m-d');
于 2013-06-18T14:20:42.330 回答
0

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);
于 2013-06-18T14:21:33.130 回答
0

您需要使用DATE()功能,您的查询应该看起来像

->select("DATE(`created_at`) AS created_at",FALSE) // to avoid additional bacticks
于 2013-06-18T14:24:44.033 回答
0

期待您使用 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;

于 2013-06-18T15:06:19.120 回答