Get 30 days older records from table in laravel
Get 30 days older records from table in laravel
In this session, we’ll try our hand at solving the "Get 30 days older records from table in laravel" puzzle by using the computer language.
Sometimes you have to get the 30 days older records from table in laravel. In the case, this code snippet will help you to get the 30 days older records from the current date from a table.-
Laravel eloquent to get 30 days older records from today's date
//1. WhereRaw() Eloquent Query: $users = \App\Models\User::whereRaw('DATEDIFF(NOW(), created_at) > 30')->get(); dd($users); //2. whereDate() Eloquent Query: $users = \App\Models\User::whereDate('created_at', '<=', now()->subDays(30))->get(); dd($users);
This code snippet will helps you to get all the records which are 30 days older from today's date and return the records as output. You can use any one of the provided code snippet to get all the records which are 30 days older from current date.
-
Get 30 days older records from current date using whereBetween method in Laravel
$startDate = Carbon\Carbon::now()->subDays(30); $endDate = Carbon\Carbon::now(); $users = App\Models\User::select("*")->whereBetween('created_at', [$startDate, $endDate])->get(); dd($users);
This code snippet will help you to get the records from users table which are created between current date and created 30 days before of current date.
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
- Laravel onclick function not working
- How to run a specific seeder class in laravel
- How to insert multiple rows in mysql using loop in laravel?
- Trying to get property 'title' of non-object
- How to display pivot table column value in laravel
- Use withCount() to get total number of records with relationship
- How to use or operator in laravel
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Display message with session flash using bootstrap alert class in laravel
- Command to create MySQL Docker image and access the MySQL command-line interface (CLI) within a running Docker container
- How to return a column with different name in Laravel
- How to start websocket server in laravel
- How to create project_user pivot table in laravel
- How to get only time from created_at in laravel
- Display success message in laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- How to pass data to route in laravel?
- How to delete record in Laravel with ajax
- How to prevent host header attack in Laravel
- Laravel get single row by id
- How to pass data to multiple partial view files in laravel
- How to pass data to partial view file in laravel
- Conditional validation in laravel
- Session Doesn't Work on Redirect
- How to get last year records count with month wise in Laravel