I'm using Laravel Framework.
I want all of the rows for this day. This is what I tried:
DB::table('users')->where('created_at', '>=', date('Y-m-d H:i:s'))
(field created_at
represented in database in format: Y-m-d H:i:s
).
Comparing date using raw query in laravel we will use DB::raw method to compare this. $users = DB::table('users') ->where('created_at', '2016-12-31') ->get(); //or $users = DB::table('users') ->where(\DB::raw('date("created_at")', '2021') ->get(); Comparing date in using operators like greater then equal to etc.
The whereBetween() method is a query builder chained alongside other Laravel query builders used to fetch data from the database. The whereBetween() method queries the database table to fetch rows of records from the database within a range of values.
Hmmm...there was a good answer to this question which seems to have now disappeared.*
It was something like this:
User::where('created_at', '>=', new DateTime('today'))
Note: if you're putting this code in a file with a namespace, or might use a namespace in the future, you should prefix the DateTime class with a backslash: new \DateTime('today')
.
* https://stackoverflow.com/questions/15052679/laravel-framework-how-to-get-today-queries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With