C
C
connor742016-02-02 21:23:05
Yii
connor74, 2016-02-02 21:23:05

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

1 answer(s)
L
LAV45, 2016-02-02
@LAV45

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

Ask a Question

731 491 924 answers to any question