mstdmstd
mstdmstd

Reputation: 626

How to make grouped request by only day part of created_at?

In my my laravel 5.7.3 application , I need to get grouped date like

$voteItemUsersResults = VoteItemUsersResult::orderBy('created_at', 'desc')
             ->groupBy('created_at')
             ->having('created_at', '>', '2018-09-01')
             ->get();

but I need to get only day part of created_at, without time.

Which is the valid way to make it ?

Upvotes: 0

Views: 50

Answers (1)

Mohammad
Mohammad

Reputation: 497

Grouped by Only Day of Datetime .

$voteItemUsersResults = VoteItemUsersResult::orderBy('created_at', 'desc')
             ->groupBy(DB::raw('DATE_FORMAT(created_at, "%d")'))
             ->having('created_at', '>', '2018-09-01')
             ->get();

Upvotes: 1

Related Questions