in this tutorial, we see how to get last 30 days record in laravel 8. You can simply get the last 30 days record using laravel 8 eloquent model. In PHP, you can use INTERVAL to get the last 30 days record from the database. Also, we can see how to get the last 1 month's data records in laravel 6/7/8 using Carbon functions.
For MySQL query, we use the INTERVAL operator. It is mainly used to calculate the date and time values.
So, let's see get last 30 days records in laravel 6, laravel 7 and laravel 8. how to get last 30 days record in PHP, how to get last 30 days record in MySQL.
SQL query to get records from the last 30 days in MySQL.
select * from users where created_at > now() - INTERVAL 30 day;
You can also use the current_date instead of now() function
select * from users where created_at > current_date - interval 30 day;
In laravel, we are using the carbon subdays function to get the last 30 days records.
$date = \Carbon\Carbon::today()->subDays(30);
$users = User::where('created_at','>=',$date)->get();
You might also like :
Hello, laravel web developers! In this article, we'll see how to convert Word doc to PDF in laravel 11. In laravel 1...
Jul-01-2024
In this article, we will see what is new in laravel 9 and the features of laravel 9. Laravel 9 is recently released...
Feb-13-2022
In this example we will see how to convert html to pdf using javaScript. PDF file format is very useful to dow...
Aug-23-2021
In this article, we will see how to run the python scripts in laravel 9. Python is a popular programming language.&...
May-07-2022