Answer the question
In order to leave comments, you need to log in
How to make a grouped output by month?
Good time of the day.
There is data - events (name), indicating the start date and end date (date_begin, date_end).
How can I display them on the page as:
January 2016
- Event 1
- Event 2
February 2016
- Event 3
... etc.
New to Yii. I will be very grateful!
Answer the question
In order to leave comments, you need to log in
$data = Event::find()
->select([
'name',
'date_begin',
// делим на 60 * 60 * 24 * 30 и отбрасываем бробную часть после деления
'date' => 'TRUNCATE(date_begin / 2592000, 0)'
])
// ->where([ ... ])
->orderBy(['date_begin' => SORT_DESC])
->indexBy('date')
->asArray()
->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question