Joyanta sarkar
Joyanta sarkar

Reputation: 113

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?

Upvotes: 1

Views: 335

Answers (1)

KyleK
KyleK

Reputation: 5056

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

Upvotes: 2

Related Questions