Let's get started quickly. We have a schedule of articles and we want to get the articles for the month and year we are in :-
$articles = Article::whereMonth('created_at',\Carbon\Carbon::now()->month)
->whereYear('created_at', \Carbon\Carbon::now()->year)
->get();
dd($articles);
We will also use SQL MONTH function with PHP date() function :-
$articles = \DB::table('articles')
->whereRaw('MONTH(created_at) = ?',[date('m')])
->whereRaw('YEAR(created_at) = ?',[date('Y')])
->get();
dd($articles);
I wish you a happy code.
Top comments (0)