Convert mysql query result timestamp to date format - use of date, DATE_FORMAT and FROM_UNIXTIME

No processing of query results

$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;

result
Insert image description here

Convert to date format

$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;

result
Insert image description here

Custom date format

$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') as trade_date")
    ->group("pid, gid, trade_date")
    ->select()
    ->toArray();
var_dump($res);die;

result
Insert image description here

end

Giving roses to others will leave a lingering fragrance in your hands! If the content of the article is helpful to you, please don't be stingy with your 点赞评论和关注 so that I can receive feedback as soon as possible. Every time you 支持 The greatest motivation for creation. Of course, if you find 存在错误 or 更好的解决方法 in the article, you are welcome to comment and send me a private message!

Good, I am向宇,https://xiangyu.blog.csdn.net

A developer who has been working quietly in a small company recently started studying Unity by himself out of interest. If you encounter any problems, you are also welcome to comment and send me a private message. Although I may not necessarily know some of the questions, I will check the information from all parties and try to give the best suggestions. I hope to help more people who want to learn programming. People, encourage each other~
Insert image description here

Guess you like

Origin blog.csdn.net/qq_36303853/article/details/134955204