Answer the question
In order to leave comments, you need to log in
How to group query result by date (timestamp) in yii2?
Article table example:
id
title
text
sort_date Query
example:
Article::find()->orderBy('sort_date DESC')->limit(10)->All(),
Answer the question
In order to leave comments, you need to log in
$articles=Article::find()->orderBy('sort_date DESC')->limit(10)->All();
$sorted_articles=[];
foreach($articles as $article){
$dt=date('d.m.Y',$article->sort_date);
$sorted_articles[$dt][]=$article;
}
Try something like
->select('article.*, DATE_FORMAT(FROM_UNIXTIME(`article.sort_date`), \'%d.%m.%Y\') as date')
->orderBy('sort_date')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question