In this post, i give you example query of how to fetch current month records from table using Laravel query builder. We sometimes require to get records that created on current month. We can get current month records in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 application.
Fetch todays data
<?php
$today = date("d");
$todays_order = DB::table('service_checkout')
->whereDay('created_at', $today)
->count();
?>
Fetch current month data
<?php
$thismonth = date("m");
$todays_order = DB::table('service_checkout')
->whereMonth('created_at', $thismonth)
->count();
?>
Fetch current year data
<?php
$thisYear = date("Y");
$todays_order = DB::table('service_checkout')
->whereYear('created_at', $thisYear)
->count();
?>