Samuel Belo
Samuel Belo

Reputation: 89

How to compare simple date with datetime in Laravel?

On my project, I created an option for the user to search by date, but in my database, all the inserts are in DateTime format (yyyy-mm-dd h:m:s), while the search is made only with a simple date(yyyy-mm-dd) input. Is there any way I can compare these two values, so the user can find all the inserts on the given date?

Upvotes: 0

Views: 1212

Answers (1)

Hery Kurniawan
Hery Kurniawan

Reputation: 374

you can use eloquent whereDate with format Y-m-d

YourModel::whereDate('created_at','2021-11-24')->get();

or without model

DB::table('your_table')->whereDate('created_at','2021-11-24')->get();

Upvotes: 1

Related Questions