Skip to content

Instantly share code, notes, and snippets.

@sonichandni
Last active May 4, 2023 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonichandni/99f143ac48b4e9064a534199545dfa88 to your computer and use it in GitHub Desktop.
Save sonichandni/99f143ac48b4e9064a534199545dfa88 to your computer and use it in GitHub Desktop.
date wise data
use Carbon\Carbon;
use DB;
// For today
$activationKeyCount['today'] = KeyBatchGroupKeys::select('id')->whereDate('d_activation_date', Carbon::today())->count();
// For yesterday
$activationKeyCount['yesterday'] = KeyBatchGroupKeys::select('id')->whereDate('d_activation_date', Carbon::yesterday())->count();
// For this week
$startOfWeek = Carbon::now()->startOfWeek()->setTime(0, 0, 0);
$endOfWeek = Carbon::now()->endOfWeek()->setTime(23, 59, 59);
$activationKeyCount['this_week'] = KeyBatchGroupKeys::select('id')->whereBetween('d_activation_date', [$startOfWeek, $endOfWeek])->count();
// For this month
$startOfMonth = Carbon::now()->startOfMonth()->setTime(0, 0, 0);
$endOfMonth = Carbon::now()->endOfMonth()->setTime(23, 59, 59);
$activationKeyCount['this_month'] = KeyBatchGroupKeys::select('id')->whereBetween('d_activation_date', [$startOfMonth, $endOfMonth])->count();
// For this year
$startOfYear = Carbon::now()->startOfYear()->setTime(0, 0, 0);
$endOfYear = Carbon::now()->endOfYear()->setTime(23, 59, 59);
$activationKeyCount['this_year'] = KeyBatchGroupKeys::select('id')->whereBetween('d_activation_date', [$startOfYear, $endOfYear])->count();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment