H
H
hollanditkzn2017-10-03 09:58:39
Yii
hollanditkzn, 2017-10-03 09:58:39

How to group datetime by date?

I have a question, the date is stored in datetime format, I need to do something like this
===10/2/2017===
08:00 message
text 8:20 message text
===10/3/2017===
14:00 message text
15 :00 message text
Approximately grouped like this, but the question arose, how to group only the day of messages?
Comment::find()->groupBy(['date'])->all()
Whether there it is necessary to translate everything into unix date format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mykola, 2017-10-03
@hollanditkzn

$items = Comment::find()->addSelect(['DATE(date) as just_date'])->asArray()->all();
$items = ArrayHelper::index($items , null, 'just_date');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question