Saturday, July 11, 2026
HomeLanguagesHow to Get Last 1, 3, 6, 12 Months Data in Laravel

How to Get Last 1, 3, 6, 12 Months Data in Laravel

To get the last 30 days and 3, 6, 12 months data in laravel; Through this tutorial, you will learn how to get the last 1, 3, 6, 12 months and last month in laravel.

How to Get Last 1, 3, 6, 12 Months Data in Laravel

Use the following laravel eloquent queries to get last 3, 6, 12 month data and last 30 days data in laravel:

  • To Get Last 3 Months Data in Laravel
  • To Get Last 6, 12 Months Data in Laravel
  • Get Last 15 Days & 30 Days Data in Laravel

To Get Last 3 Months Data in Laravel

Use the following laravel eloquent query to get 3 month data or record from database tables in laravel; as shown below:

       $items = Item::select('*')
                        ->whereBetween('created_at', 
                            [Carbon::now()->subMonth(3), Carbon::now()]
                        )
                        ->get();
  

To Get Last 6, 12 Months Data in Laravel

Use the following laravel eloquent query to get 6, 12 month data or record from database tables in laravel; as shown below:

       // for last 6 month data
       $items = Item::select('*')
                        ->whereBetween('created_at', 
                            [Carbon::now()->subMonth(6), Carbon::now()]
                        )
                        ->get();


       // for last 12 month data
       $items = Item::select('*')
                        ->whereBetween('created_at', 
                            [Carbon::now()->subMonth(12), Carbon::now()]
                        )
                        ->get();


  

Get Last 15 Days & 30 Days Data in Laravel

If You want to get the last 15 days and last 30 days records from the database in laravel. Use the below given laravel eloquent query:

$last_15_days = User::where('created_at','>=',Carbon::now()->subdays(15))->get(['name','created_at']);

 $last_30_days = User::where('created_at','>=',Carbon::now()->subdays(30))->get(['name','created_at']);
Recommended:-Laravel Try Catch

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6901 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12111 POSTS0 COMMENTS
Shaida Kate Naidoo
7021 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS