Count todays, Current month and Current year data in Laravel

Count todays, Current month and Current year data in Laravel

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(); 

?>

Leave a Reply