Skip to main content

whereDate() and other whereX Methods

Premium
1:04

What if you have a timestamp or datetime column and want to query by date? How do you filter that? There are a few ways to use raw queries, but I will show you a few helpful methods in Laravel.


Example 1: DB::raw()

Because created_at is a datetime column, the SQL date function can be used.

User::where(\DB::raw('DATE('created_at)'), '2024-03-01')->first();

And, of course, it returns the user registered on that date.


Example 2: whereDate()

Instead of doing DB::raw() and using SQL functions, you can use the whereDate() Eloquent method.

User::whereDate('created_at', '2024-03-01')->first();

Also, instead of date, you can check...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 41 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.