How to get data between two dates in laravel 9

How to get data between two dates in laravel 9.png

Let see how can we get data between two dates in Laravel 9. Example if we want to show data only a give date mean start and end date we can implement by simple way. I will show example with code.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Post;
use Carbon\Carbon;
class UserController extends Controller
    public function index(Request $request)
        $start = Carbon::createFromFormat('d/m/Y', '20/11/2022');
        $end = Carbon::createFromFormat('d/m/Y', '28/11/2022');
        $post = Post::select('id', 'post_title', 'post_author','post_slug', 'created_at')
                        ->whereBetween('created_at', [$start, $end])

About author


Muhammad Zubair

My name is Muhammad Zubair. I'm a full-stack developer. I'm a owner of I love to write tutorials of PHP, Laravel, Html & css, Javascript, Java and much more with examples.


No Comments Yet.

Leave a Reply