
wheredate in laravel not working
wheredate in laravel not working
In this session, we’ll try our hand at solving the "wheredate in laravel not working" puzzle by using the computer language.
There could be any issue in script while comparing with column's value that's why wheredate method is not working. WhereDate method is used to compare a column's value against a date in laravel-
Laravel whereDate() method on created_at field
$users = User::whereDate('created_at', '=', date('Y-m-d'))->get(); return $users; //Or $users = User::whereDate('created_at', '=', '2021-8-31')->get(); return $users;
Output:
[{"id":16,"name":"Kayla","email":"[email protected]","email_verified_at":null,
"created_at":"2021-08-31T08:24:43.000000Z","updated_at":"2021-08-31T08:24:43.000000Z"}]This code snippet will help you to get the records from users table on the base of current (today) date. You can pass date "2021-8-31" in ('Y-M-D') format as third argument to whereDate() method to get the record of specific date from table.
-
Laravel whereDate() method on created_at field with dynamic value
//2021-08-02 $users = User::whereDate('created_at', '=', User::find(1)->created_at->toDateString())->get(); return $users; //2021-08-02 $users = User::whereDate('created_at', '=', User::find(1)->created_at->format('Y-m-d'))->get(); return $users; //Output : [{"id":16,"name":"Kayla","email":"[email protected]","email_verified_at":null,"created_at":"2021-08-02T08:24:43.000000Z","updated_at":"2021-08-31T08:24:43.000000Z"}]
You can pass dynamic value to whereDate method using created_at() and toDateString() method on create_at attribute. The method format() and toDataString() convert the timestamp (date and time) value into date format.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- The openssl extension is required for SSL/TLS protection but is not available
- How to get selected categories on edit record with Select2
- Update email with unique validation in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- Run artisan command to generate key in laravel
- Laravel 7 login error message not showing
- How to pass link from controller to view in laravel on ajax call
- Insert Comma Separated Values in laravel
- Include External CSS and JS file in Laravel
- Count all and get 10 records after where condition in laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- Laravel create table migration with model
- Laravel hasmany select not working
- Delete all related comments on deleting a post in Laravel
- How to create belongstomany relation using custom name on custom pivot table
- Page loader in laravel
- Skip first n record and display rest records in laravel view
- How to get column names from table in Laravel
- Update record after find method in lavavel
- Delete records with relationship in laravel
- Datetime field in Laravel migration
- Generate unique username in Laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to get count of all records created at yesterday
- How to get CSRF token in laravel controller