不做处理查询结果
$res = OrderAdmin::where('status', 1) ->whereTime('trade_time', 'between', [$startDate, $endDate]) ->order('trade_time desc') ->field("sum(money) as sum_money,pid, gid, trade_time as trade_date") ->group("pid, gid, trade_date") ->select() ->toArray(); var_dump($res);die;
结果
转成日期格式
$res = OrderAdmin::where('status', 1) ->whereTime('trade_time', 'between', [$startDate, $endDate]) ->order('trade_time desc') ->field("sum(money) as sum_money,pid, gid, date(FROM_UNIXTIME(trade_time)) as trade_date") ->group("pid, gid, trade_date") ->select() ->toArray(); var_dump($res);die;
结果
自定义日期格式
$res = OrderAdmin::where('status', 1) ->whereTime('trade_time', 'between', [$startDate, $endDate]) ->order('trade_time desc') ->field("sum(money) as sum_money,pid, gid, DATE_FORMAT(FROM_UNIXTIME(trade_time), '%Y-%m-%d %H:%i:%s') as trade_date") ->group("pid, gid, trade_date") ->select() ->toArray(); var_dump($res);die;
结果
ps:时间转化到时分秒可以使用DATE_FORMAT(FROM_UNIXTIME(trade_time), '%Y-%m-%d %H:%i:%s')
,也可以直接使用FROM_UNIXTIME(trade_time)
,效果是一样的