Search code examples
laravel-8php-carbon

Count Number of Friday in current month in Laravel using Carbon


How can I find the number of Friday in the current month? I can use Carbon in my project.

I have used Carbon::now()->Friday(); This isn't working. Can anybody help?


Solution

  • $now = CarbonImmutable::now();
    echo CarbonPeriod::create($now->startOfMonth(), $end->endOfMonth())
      ->filter(static fn ($date) => $date->is('Friday'))
      ->count();