Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中,仅从yy mm dd hr min sec格式中选择日期_Php_Mysql_Codeigniter_Datatables - Fatal编程技术网

Php 在codeigniter中,仅从yy mm dd hr min sec格式中选择日期

Php 在codeigniter中,仅从yy mm dd hr min sec格式中选择日期,php,mysql,codeigniter,datatables,Php,Mysql,Codeigniter,Datatables,我在创建了一个字段,格式为yy mm dd hr min sec。。现在,如何仅选择此字段的日期部分 function customers(){ $this->datatables ->select('created_at') ->group_by('email') ->from('customers') echo $this->datatables->generate(); } 如何注册这些内容?将created

我在创建了一个字段,格式为yy mm dd hr min sec。。现在,如何仅选择此字段的日期部分

function customers(){

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

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

如何注册这些内容?

将created_at字段中的值设置为$result

$date = new DateTime($result);
echo $date->format('Y-m-d');

可以使用SUBSTRING命令在查询中执行以下操作:

->select('SUBSTRING(created_at,1,8)')
(注意,第一个字符从索引1开始)

但是,在生成的PHP代码中这样做会更好地提高性能

echo substr($data->created_at,0,8);
您需要使用
DATE()
函数,您的查询应该如下所示

->select("DATE(`created_at`) AS created_at",FALSE) // to avoid additional bacticks

希望您正在使用MYSQL


然后,您只需要在查看时创建

日期字段在哪里?“$var='yy-mm-dd hr-min-sec'$var=日期('y-m-d',标准时间($var))`对不起,伙计们。。我已经编辑了代码。。。你现在可以看一下吗?我同意在PHP代码中这样做是可行的。DateTime也比substr()更有用,如我的回答所示。
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();

   }