Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: select entries created in the same day

I have a Laravel model, Users. It utilizes standard Laravel's timestamp: created_at and updated_at.

I want to find Users created on the same date as the given user.

The problem is I can't directly compare database fields, as those fields also contain the time, like so: 2016-03-27 14:46:30.

I want to do somehting like this:

User::where('created_at', $user->created_at);

But it doesn't seem to work that way.

Any suggestions?

like image 927
borisano Avatar asked Mar 27 '16 15:03

borisano


1 Answers

Try to use whereDate condition instead :

$q->whereDate('created_at', '=', $your_date);

Hope this helps.

like image 151
Zakaria Acharki Avatar answered Oct 17 '22 02:10

Zakaria Acharki