Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

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? (29 h 14 min)

You also get:

54 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…